Skip to content

Commit

Permalink
[Vulkan] Fix compatibility with VK_HEADER_VERSION >= 301
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Nov 7, 2024
1 parent 37bed99 commit 7f8bb27
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 51 deletions.
8 changes: 4 additions & 4 deletions lib/ivis_opengl/3rdparty/vkh_info.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// VkhInfo
// Version: 1.3.2
// Version: 1.3.3
//
// Copyright (c) 2019-2021 past-due
// Copyright (c) 2019-2024 past-due
//
// https://github.com/past-due/vulkan-helpers
//
Expand Down Expand Up @@ -180,7 +180,7 @@ void VkhInfo::Output_InstanceLayerProperties(PFN_vkGetInstanceProcAddr _vkGetIns
}
}

void VkhInfo::Output_SurfaceInformation(const vk::PhysicalDevice& physicalDevice, const vk::SurfaceKHR& surface, const vk::DispatchLoaderDynamic& vkDynLoader)
void VkhInfo::Output_SurfaceInformation(const vk::PhysicalDevice& physicalDevice, const vk::SurfaceKHR& surface, const VkhInfo::DispatchLoaderDynamic& vkDynLoader)
{
std::stringstream buf;

Expand Down Expand Up @@ -237,7 +237,7 @@ void VkhInfo::Output_SurfaceInformation(const vk::PhysicalDevice& physicalDevice
}

// If `getProperties2` is true, the instance `inst` *must* have been created with the "VK_KHR_get_physical_device_properties2" extension enabled
void VkhInfo::Output_PhysicalDevices(const vk::Instance& inst, const vk::ApplicationInfo& appInfo, std::vector<const char*> instanceExtensions, const vk::DispatchLoaderDynamic& vkDynLoader)
void VkhInfo::Output_PhysicalDevices(const vk::Instance& inst, const vk::ApplicationInfo& appInfo, std::vector<const char*> instanceExtensions, const VkhInfo::DispatchLoaderDynamic& vkDynLoader)
{
std::stringstream buf;

Expand Down
13 changes: 9 additions & 4 deletions lib/ivis_opengl/3rdparty/vkh_info.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// VkhInfo
// Version: 1.3.2
// Version: 1.3.3
//
// Copyright (c) 2019-2021 past-due
// Copyright (c) 2019-2024 past-due
//
// https://github.com/past-due/vulkan-helpers
//
Expand Down Expand Up @@ -47,6 +47,11 @@ class VkhInfo
{
public:
typedef std::function<void (const std::string& output)> outputHandlerFuncType;
#if VK_HEADER_VERSION >= 301
using DispatchLoaderDynamic = vk::detail::DispatchLoaderDynamic;
#else
using DispatchLoaderDynamic = vk::DispatchLoaderDynamic;
#endif

VkhInfo() {}
VkhInfo(const outputHandlerFuncType& outputHandler);
Expand All @@ -58,10 +63,10 @@ class VkhInfo
void Output_GlobalInstanceExtensions(PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr);
void Output_InstanceLayerProperties(PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr);

void Output_SurfaceInformation(const vk::PhysicalDevice& physicalDevice, const vk::SurfaceKHR& surface, const vk::DispatchLoaderDynamic& vkDynLoader);
void Output_SurfaceInformation(const vk::PhysicalDevice& physicalDevice, const vk::SurfaceKHR& surface, const VkhInfo::DispatchLoaderDynamic& vkDynLoader);

// If `getProperties2` is true, the instance `inst` *must* have been created with the "VK_KHR_get_physical_device_properties2" extension enabled
void Output_PhysicalDevices(const vk::Instance& inst, const vk::ApplicationInfo& appInfo, std::vector<const char*> instanceExtensions, const vk::DispatchLoaderDynamic& vkDynLoader);
void Output_PhysicalDevices(const vk::Instance& inst, const vk::ApplicationInfo& appInfo, std::vector<const char*> instanceExtensions, const VkhInfo::DispatchLoaderDynamic& vkDynLoader);

public:

Expand Down
48 changes: 24 additions & 24 deletions lib/ivis_opengl/gfx_api_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// To maintain compatibility with as many systems as possible:
// 1.) Ensure Vulkan 1.0 compatibility
// 2.) Avoid *requiring* anything outside of the scope of the "Vulkan Portable Subset"
// 3.) All calls to Vulkan APIs should use dynamic dispatch (see the uses of vk::DispatchLoaderDynamic in this file)
// 3.) All calls to Vulkan APIs should use dynamic dispatch (see the uses of WZ_vk::DispatchLoaderDynamic in this file)
// 4.) Test with the Vulkan validation layers enabled (run WZ with --gfxdebug)
//
// #2 means the following things are currently best avoided:
Expand Down Expand Up @@ -258,7 +258,7 @@ static uint32_t findProperties(const vk::PhysicalDeviceMemoryProperties& memprop
abort();
}

bool checkFormatSupport(const vk::PhysicalDevice& physicalDevice, vk::Format format, vk::ImageTiling tiling, vk::FormatFeatureFlags features, const vk::DispatchLoaderDynamic& vkDynLoader)
bool checkFormatSupport(const vk::PhysicalDevice& physicalDevice, vk::Format format, vk::ImageTiling tiling, vk::FormatFeatureFlags features, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
vk::FormatProperties props;
physicalDevice.getFormatProperties(format, &props, vkDynLoader);
Expand All @@ -274,7 +274,7 @@ bool checkFormatSupport(const vk::PhysicalDevice& physicalDevice, vk::Format for
return false;
}

vk::Format findSupportedFormat(const vk::PhysicalDevice& physicalDevice, const std::vector<vk::Format>& candidates, vk::ImageTiling tiling, vk::FormatFeatureFlags features, const vk::DispatchLoaderDynamic& vkDynLoader) {
vk::Format findSupportedFormat(const vk::PhysicalDevice& physicalDevice, const std::vector<vk::Format>& candidates, vk::ImageTiling tiling, vk::FormatFeatureFlags features, const WZ_vk::DispatchLoaderDynamic& vkDynLoader) {
for (vk::Format format : candidates)
{
if (checkFormatSupport(physicalDevice, format, tiling, features, vkDynLoader))
Expand All @@ -286,7 +286,7 @@ vk::Format findSupportedFormat(const vk::PhysicalDevice& physicalDevice, const s
throw std::runtime_error("failed to find supported format!");
}

QueueFamilyIndices findQueueFamilies(const vk::PhysicalDevice &device, const vk::SurfaceKHR &surface, const vk::DispatchLoaderDynamic &vkDynLoader)
QueueFamilyIndices findQueueFamilies(const vk::PhysicalDevice &device, const vk::SurfaceKHR &surface, const WZ_vk::DispatchLoaderDynamic &vkDynLoader)
{
QueueFamilyIndices indices;

Expand Down Expand Up @@ -327,7 +327,7 @@ QueueFamilyIndices findQueueFamilies(const vk::PhysicalDevice &device, const vk:
return indices;
}

SwapChainSupportDetails querySwapChainSupport(const vk::PhysicalDevice &device, const vk::SurfaceKHR &surface, const vk::DispatchLoaderDynamic &vkDynLoader)
SwapChainSupportDetails querySwapChainSupport(const vk::PhysicalDevice &device, const vk::SurfaceKHR &surface, const WZ_vk::DispatchLoaderDynamic &vkDynLoader)
{
SwapChainSupportDetails details;

Expand All @@ -338,7 +338,7 @@ SwapChainSupportDetails querySwapChainSupport(const vk::PhysicalDevice &device,
return details;
}

std::vector<const char*> findSupportedDeviceExtensions(const vk::PhysicalDevice &device, const std::vector<const char*> &desiredExtensions, const vk::DispatchLoaderDynamic &vkDynLoader)
std::vector<const char*> findSupportedDeviceExtensions(const vk::PhysicalDevice &device, const std::vector<const char*> &desiredExtensions, const WZ_vk::DispatchLoaderDynamic &vkDynLoader)
{
const auto availableExtensions = device.enumerateDeviceExtensionProperties(nullptr, vkDynLoader); // TODO: handle thrown error?
std::unordered_set<std::string> supportedExtensionNames;
Expand All @@ -363,7 +363,7 @@ std::vector<const char*> findSupportedDeviceExtensions(const vk::PhysicalDevice
return foundExtensions;
}

bool checkDeviceExtensionSupport(const vk::PhysicalDevice &device, const std::vector<const char*> &desiredExtensions, const vk::DispatchLoaderDynamic &vkDynLoader)
bool checkDeviceExtensionSupport(const vk::PhysicalDevice &device, const std::vector<const char*> &desiredExtensions, const WZ_vk::DispatchLoaderDynamic &vkDynLoader)
{
try {
const auto availableExtensions = device.enumerateDeviceExtensionProperties(nullptr, vkDynLoader);
Expand Down Expand Up @@ -449,7 +449,7 @@ vk::SampleCountFlagBits getMaxUsableSampleCount(const vk::PhysicalDeviceProperti
return vk::SampleCountFlagBits::e1;
}

vk::Format findDepthStencilFormat(const vk::PhysicalDevice& physicalDevice, const vk::DispatchLoaderDynamic& vkDynLoader)
vk::Format findDepthStencilFormat(const vk::PhysicalDevice& physicalDevice, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
return findSupportedFormat(
physicalDevice,
Expand All @@ -460,7 +460,7 @@ vk::Format findDepthStencilFormat(const vk::PhysicalDevice& physicalDevice, cons
);
}

vk::Format findDepthBufferFormat(const vk::PhysicalDevice& physicalDevice, const vk::DispatchLoaderDynamic& vkDynLoader)
vk::Format findDepthBufferFormat(const vk::PhysicalDevice& physicalDevice, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
std::vector<vk::Format> depthFormats = { vk::Format::eD32SfloatS8Uint, vk::Format::eD32Sfloat, vk::Format::eD24UnormS8Uint };
return findSupportedFormat(
Expand All @@ -472,7 +472,7 @@ vk::Format findDepthBufferFormat(const vk::PhysicalDevice& physicalDevice, const
);
}

vk::Format findSceneColorBufferFormat(const vk::PhysicalDevice& physicalDevice, const vk::DispatchLoaderDynamic& vkDynLoader)
vk::Format findSceneColorBufferFormat(const vk::PhysicalDevice& physicalDevice, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
std::vector<vk::Format> sceneColorFormats = { vk::Format::eA2B10G10R10UnormPack32, vk::Format::eR8G8B8A8Unorm };
return findSupportedFormat(
Expand Down Expand Up @@ -750,7 +750,7 @@ void BlockBufferAllocator::clean()
constexpr uint32_t descriptorPoolMaxSetsDefault = 10000;
constexpr uint32_t descriptorPoolSizeDescriptorCountDefault = 10000;

perFrameResources_t::perFrameResources_t(vk::Device& _dev, const VmaAllocator& allocator, const uint32_t& graphicsQueueFamilyIndex, const vk::DispatchLoaderDynamic& vkDynLoader)
perFrameResources_t::perFrameResources_t(vk::Device& _dev, const VmaAllocator& allocator, const uint32_t& graphicsQueueFamilyIndex, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
: dev(_dev)
, allocator(allocator)
, stagingBufferAllocator(allocator, 1024 * 1024, vk::BufferUsageFlagBits::eTransferSrc, VMA_MEMORY_USAGE_CPU_ONLY)
Expand Down Expand Up @@ -939,7 +939,7 @@ perFrameResources_t::~perFrameResources_t()
clean();
}

void perFrameResources_t::DescriptorPoolsContainer::reset(vk::Device dev, const vk::DispatchLoaderDynamic& vkDynLoader)
void perFrameResources_t::DescriptorPoolsContainer::reset(vk::Device dev, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
for (auto& descriptorPool : pools)
{
Expand Down Expand Up @@ -973,7 +973,7 @@ bool buffering_mechanism::isInitialized()
return !perFrameResources.empty();
}

perSwapchainImageResources_t::perSwapchainImageResources_t(vk::Device& _dev, const vk::DispatchLoaderDynamic& vkDynLoader)
perSwapchainImageResources_t::perSwapchainImageResources_t(vk::Device& _dev, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
: dev(_dev)
, pVkDynLoader(&vkDynLoader)
{
Expand All @@ -989,7 +989,7 @@ perSwapchainImageResources_t::~perSwapchainImageResources_t()

// MARK: buffering_mechanism

void buffering_mechanism::init(vk::Device dev, const VmaAllocator& allocator, size_t swapChainImageCount, const uint32_t& graphicsQueueFamilyIndex, const vk::DispatchLoaderDynamic& vkDynLoader)
void buffering_mechanism::init(vk::Device dev, const VmaAllocator& allocator, size_t swapChainImageCount, const uint32_t& graphicsQueueFamilyIndex, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
currentFrame = 0;
currentSwapchainImageResourcesFrame = 0;
Expand All @@ -1014,15 +1014,15 @@ size_t buffering_mechanism::numFrames()
return perFrameResources.size();
}

void buffering_mechanism::destroy(vk::Device dev, const vk::DispatchLoaderDynamic& vkDynLoader)
void buffering_mechanism::destroy(vk::Device dev, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
perFrameResources.clear();
perSwapchainImageResources.clear();
currentFrame = 0;
currentSwapchainImageResourcesFrame = 0;
}

void buffering_mechanism::swap(vk::Device dev, const vk::DispatchLoaderDynamic& vkDynLoader, bool skipAcquireNewSwapchainImage)
void buffering_mechanism::swap(vk::Device dev, const WZ_vk::DispatchLoaderDynamic& vkDynLoader, bool skipAcquireNewSwapchainImage)
{
currentFrame = (currentFrame < (perFrameResources.size() - 1)) ? currentFrame + 1 : 0;
if (!skipAcquireNewSwapchainImage)
Expand Down Expand Up @@ -1209,7 +1209,7 @@ std::vector<uint32_t> VkPSO::readShaderBuf(const std::string& name)
return buffer;
}

vk::ShaderModule VkPSO::get_module(const std::string& name, const vk::DispatchLoaderDynamic& vkDynLoader)
vk::ShaderModule VkPSO::get_module(const std::string& name, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
const auto tmp = readShaderBuf(name);
ASSERT_OR_RETURN(vk::ShaderModule(), tmp.size() > 0, "Failed to read shader: %s", name.c_str());
Expand Down Expand Up @@ -1627,7 +1627,7 @@ VkPSO::VkPSO(vk::Device _dev,
vk::RenderPass rp,
const std::shared_ptr<VkhRenderPassCompat>& renderpass_compat,
vk::SampleCountFlagBits rasterizationSamples,
const vk::DispatchLoaderDynamic& _vkDynLoader,
const WZ_vk::DispatchLoaderDynamic& _vkDynLoader,
const VkRoot& _root
) : dev(_dev), pVkDynLoader(&_vkDynLoader), renderpass_compat(renderpass_compat), root(&_root)
{
Expand Down Expand Up @@ -2147,7 +2147,7 @@ VkDepthMapImage::~VkDepthMapImage()
}
}

void VkDepthMapImage::destroy(vk::Device _dev, const VmaAllocator& allocator, const vk::DispatchLoaderDynamic& vkDynLoader)
void VkDepthMapImage::destroy(vk::Device _dev, const VmaAllocator& allocator, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
if (buffering_mechanism::isInitialized())
{
Expand Down Expand Up @@ -2372,7 +2372,7 @@ VkRenderedImage::~VkRenderedImage()
}
}

void VkRenderedImage::destroy(vk::Device _dev, const VmaAllocator& allocator, const vk::DispatchLoaderDynamic& vkDynLoader)
void VkRenderedImage::destroy(vk::Device _dev, const VmaAllocator& allocator, const WZ_vk::DispatchLoaderDynamic& vkDynLoader)
{
if (buffering_mechanism::isInitialized())
{
Expand Down Expand Up @@ -2664,7 +2664,7 @@ static bool createGPUImageAndViewInternal(const vk::PhysicalDevice& physicalDevi
const vk::Extent2D& extent, vk::SampleCountFlagBits msaaSamples, vk::Format imageFormat,
const vk::ImageUsageFlags imageUsageFlags, const vk::ImageAspectFlags& subresourceAspectFlags,
vk::Image& outputImage, vk::DeviceMemory& outputMemory, vk::ImageView& outputView,
const vk::DispatchLoaderDynamic& vkDynLoader, const char *loggingKey)
const WZ_vk::DispatchLoaderDynamic& vkDynLoader, const char *loggingKey)
{
if (loggingKey == nullptr)
{
Expand Down Expand Up @@ -2746,7 +2746,7 @@ static bool createGPUImageAndViewInternal(const vk::PhysicalDevice& physicalDevi
static bool createColorAttachmentImage(const vk::PhysicalDevice& physicalDevice, const vk::PhysicalDeviceMemoryProperties& memprops, const vk::Device& dev,
const vk::Extent2D& swapchainSize, vk::SampleCountFlagBits msaaSamples, vk::Format colorFormat,
vk::Image& colorImage, vk::DeviceMemory& colorImageMemory, vk::ImageView& colorImageView,
const vk::DispatchLoaderDynamic& vkDynLoader, const char *loggingKey = "colorImage")
const WZ_vk::DispatchLoaderDynamic& vkDynLoader, const char *loggingKey = "colorImage")
{
return createGPUImageAndViewInternal(physicalDevice, memprops, dev,
swapchainSize, msaaSamples, colorFormat,
Expand All @@ -2759,7 +2759,7 @@ static bool createColorAttachmentImage(const vk::PhysicalDevice& physicalDevice,
static bool createDepthStencilImage(const vk::PhysicalDevice& physicalDevice, const vk::PhysicalDeviceMemoryProperties& memprops, const vk::Device& dev,
const vk::Extent2D& swapchainSize, vk::SampleCountFlagBits msaaSamples, vk::Format depthFormat,
vk::Image& depthStencilImage, vk::DeviceMemory& depthStencilMemory, vk::ImageView& depthStencilView,
const vk::DispatchLoaderDynamic& vkDynLoader, const char *loggingKey = "depthStencilImage")
const WZ_vk::DispatchLoaderDynamic& vkDynLoader, const char *loggingKey = "depthStencilImage")
{
return createGPUImageAndViewInternal(physicalDevice, memprops, dev,
swapchainSize, msaaSamples, depthFormat,
Expand Down Expand Up @@ -3510,7 +3510,7 @@ bool VkRoot::createVulkanInstance(uint32_t apiVersion, const std::vector<const c
}

// WZ-specific functions for rating / determining requirements
int rateDeviceSuitability(const vk::PhysicalDevice &device, const vk::SurfaceKHR &surface, const vk::DispatchLoaderDynamic &vkDynLoader)
int rateDeviceSuitability(const vk::PhysicalDevice &device, const vk::SurfaceKHR &surface, const WZ_vk::DispatchLoaderDynamic &vkDynLoader)
{
const auto deviceProperties = device.getProperties(vkDynLoader);
vk::PhysicalDeviceFeatures deviceFeatures = device.getFeatures(vkDynLoader);
Expand Down
Loading

0 comments on commit 7f8bb27

Please sign in to comment.