Skip to content
8 changes: 5 additions & 3 deletions include/vsg/app/WindowTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ namespace vsg
std::vector<float> queuePiorities{1.0, 0.0};
VkPipelineStageFlagBits imageAvailableSemaphoreWaitFlag = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;

bool debugLayer = false;
bool synchronizationLayer = false;
bool apiDumpLayer = false;
// hints to which extenstion to enable during Instance/Device setup
bool debugLayer = false; // VK_LAYER_KHRONOS_validation
bool synchronizationLayer = false; // VK_LAYER_KHRONOS_synchronization2
bool apiDumpLayer = false; // VK_LAYER_LUNARG_api_dump
bool debugUtils = false; // VK_EXT_debug_utils

// Device to use, if not assigned use the device preferences below
ref_ptr<vsg::Device> device;
Expand Down
1 change: 1 addition & 0 deletions include/vsg/vk/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace vsg

ref_ptr<Queue> getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex = 0);

/// get the extensions structure that holds a range of function pointers to vkInstance extensions
const Extensions* getExtensions() const { return _extensions.get(); }

/// get the address of specified function using vkGetDeviceProcAddr
Expand Down
1 change: 1 addition & 0 deletions include/vsg/vk/Extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ namespace vsg
PFN_vkCmdDrawMeshTasksIndirectEXT vkCmdDrawMeshTasksIndirectEXT = nullptr;
PFN_vkCmdDrawMeshTasksIndirectCountEXT vkCmdDrawMeshTasksIndirectCountEXT = nullptr;
};
VSG_type_name(vsg::Extensions);

} // namespace vsg
6 changes: 6 additions & 0 deletions include/vsg/vk/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

#include <vsg/core/ref_ptr.h>
#include <vsg/vk/AllocationCallbacks.h>
#include <vsg/vk/InstanceExtensions.h>

#include <vector>

Expand Down Expand Up @@ -68,6 +69,9 @@ namespace vsg
/// get a PhysicalDevice and queue family index that supports the specified queueFlags, and presentation of specified surface if one is provided.
std::tuple<ref_ptr<PhysicalDevice>, int, int> getPhysicalDeviceAndQueueFamily(VkQueueFlags queueFlags, Surface* surface, const PhysicalDeviceTypes& deviceTypePreferences = {}) const;

/// get the extensions structure that holds a range of function pointers to vkInstance extensions
const InstanceExtensions* getExtensions() const { return _extensions.get(); }

/// get the address of specified function using vkGetInstanceProcAddr.
template<typename T>
bool getProcAddr(T& procAddress, const char* pName, const char* pNameFallback = nullptr) const
Expand All @@ -86,6 +90,8 @@ namespace vsg
ref_ptr<AllocationCallbacks> _allocator;

PhysicalDevices _physicalDevices;

ref_ptr<InstanceExtensions> _extensions;
};
VSG_type_name(vsg::Instance);

Expand Down
43 changes: 43 additions & 0 deletions include/vsg/vk/InstanceExtensions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

/* <editor-fold desc="MIT License">

Copyright(c) 2023 Robert Osfield

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

</editor-fold> */

#include <vsg/core/Inherit.h>

namespace vsg
{
class Instance;

/// Extensions manages a set of Vulkan extension function pointers.
/// The vsg::Device "has a" Extensions object that can be accessed via device->getExtensions().
class VSG_DECLSPEC InstanceExtensions : public Inherit<Object, InstanceExtensions>
{
public:
explicit InstanceExtensions(Instance* instance);

// VK_EXT_debug_utils
PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT = nullptr;
PFN_vkSetDebugUtilsObjectTagEXT vkSetDebugUtilsObjectTagEXT = nullptr;
PFN_vkQueueBeginDebugUtilsLabelEXT vkQueueBeginDebugUtilsLabelEXT = nullptr;
PFN_vkQueueEndDebugUtilsLabelEXT vkQueueEndDebugUtilsLabelEXT = nullptr;
PFN_vkQueueInsertDebugUtilsLabelEXT vkQueueInsertDebugUtilsLabelEXT = nullptr;
PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT = nullptr;
PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT = nullptr;
PFN_vkCmdInsertDebugUtilsLabelEXT vkCmdInsertDebugUtilsLabelEXT = nullptr;
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT = nullptr;
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = nullptr;
PFN_vkSubmitDebugUtilsMessageEXT vkSubmitDebugUtilsMessageEXT = nullptr;
};
VSG_type_name(vsg::InstanceExtensions);

} // namespace vsg
82 changes: 82 additions & 0 deletions include/vsg/vk/vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,85 @@ typedef struct VkPhysicalDevicePortabilitySubsetPropertiesKHR {
uint32_t minVertexInputBindingStrideAlignment;
} VkPhysicalDevicePortabilitySubsetPropertiesKHR;
#endif

#ifndef VK_EXT_debug_utils
#define VK_EXT_debug_utils 1
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugUtilsMessengerEXT)
#define VK_EXT_DEBUG_UTILS_SPEC_VERSION 2
#define VK_EXT_DEBUG_UTILS_EXTENSION_NAME "VK_EXT_debug_utils"
typedef VkFlags VkDebugUtilsMessengerCallbackDataFlagsEXT;

typedef enum VkDebugUtilsMessageSeverityFlagBitsEXT {
VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT = 0x00000001,
VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT = 0x00000010,
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT = 0x00000100,
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT = 0x00001000,
VK_DEBUG_UTILS_MESSAGE_SEVERITY_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
} VkDebugUtilsMessageSeverityFlagBitsEXT;

typedef enum VkDebugUtilsMessageTypeFlagBitsEXT {
VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT = 0x00000001,
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT = 0x00000002,
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT = 0x00000004,
VK_DEBUG_UTILS_MESSAGE_TYPE_DEVICE_ADDRESS_BINDING_BIT_EXT = 0x00000008,
VK_DEBUG_UTILS_MESSAGE_TYPE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
} VkDebugUtilsMessageTypeFlagBitsEXT;
typedef VkFlags VkDebugUtilsMessageTypeFlagsEXT;
typedef VkFlags VkDebugUtilsMessageSeverityFlagsEXT;
typedef VkFlags VkDebugUtilsMessengerCreateFlagsEXT;
typedef struct VkDebugUtilsLabelEXT {
VkStructureType sType;
const void* pNext;
const char* pLabelName;
float color[4];
} VkDebugUtilsLabelEXT;

typedef struct VkDebugUtilsObjectNameInfoEXT {
VkStructureType sType;
const void* pNext;
VkObjectType objectType;
uint64_t objectHandle;
const char* pObjectName;
} VkDebugUtilsObjectNameInfoEXT;

typedef struct VkDebugUtilsMessengerCallbackDataEXT {
VkStructureType sType;
const void* pNext;
VkDebugUtilsMessengerCallbackDataFlagsEXT flags;
const char* pMessageIdName;
int32_t messageIdNumber;
const char* pMessage;
uint32_t queueLabelCount;
const VkDebugUtilsLabelEXT* pQueueLabels;
uint32_t cmdBufLabelCount;
const VkDebugUtilsLabelEXT* pCmdBufLabels;
uint32_t objectCount;
const VkDebugUtilsObjectNameInfoEXT* pObjects;
} VkDebugUtilsMessengerCallbackDataEXT;

typedef VkBool32 (VKAPI_PTR *PFN_vkDebugUtilsMessengerCallbackEXT)(
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
void* pUserData);

typedef struct VkDebugUtilsMessengerCreateInfoEXT {
VkStructureType sType;
const void* pNext;
VkDebugUtilsMessengerCreateFlagsEXT flags;
VkDebugUtilsMessageSeverityFlagsEXT messageSeverity;
VkDebugUtilsMessageTypeFlagsEXT messageType;
PFN_vkDebugUtilsMessengerCallbackEXT pfnUserCallback;
void* pUserData;
} VkDebugUtilsMessengerCreateInfoEXT;

typedef struct VkDebugUtilsObjectTagInfoEXT {
VkStructureType sType;
const void* pNext;
VkObjectType objectType;
uint64_t objectHandle;
uint64_t tagName;
size_t tagSize;
const void* pTag;
} VkDebugUtilsObjectTagInfoEXT;
#endif
1 change: 1 addition & 0 deletions src/vsg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ set(SOURCES
vk/Fence.cpp
vk/Framebuffer.cpp
vk/Instance.cpp
vk/InstanceExtensions.cpp
vk/MemoryBufferPools.cpp
vk/PhysicalDevice.cpp
vk/Queue.cpp
Expand Down
7 changes: 6 additions & 1 deletion src/vsg/app/WindowTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/app/WindowTraits.h>
#include <vsg/io/Logger.h>
#include <vsg/io/Options.h>
#include <vsg/vk/Extensions.h>
#include <vsg/vk/vulkan.h>

using namespace vsg;
Expand Down Expand Up @@ -44,6 +45,7 @@ WindowTraits::WindowTraits(const WindowTraits& traits) :
imageAvailableSemaphoreWaitFlag(traits.imageAvailableSemaphoreWaitFlag),
debugLayer(traits.debugLayer),
apiDumpLayer(traits.apiDumpLayer),
debugUtils(traits.debugUtils),
device(traits.device),
instanceExtensionNames(traits.instanceExtensionNames),
requestedLayers(traits.requestedLayers),
Expand Down Expand Up @@ -104,7 +106,10 @@ void WindowTraits::validate()
{
instanceExtensionNames.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
}

if (debugUtils && isExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
{
instanceExtensionNames.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}
if (debugLayer) requestedLayers.push_back("VK_LAYER_KHRONOS_validation");
if (apiDumpLayer) requestedLayers.push_back("VK_LAYER_LUNARG_api_dump");
if (synchronizationLayer) requestedLayers.push_back("VK_LAYER_KHRONOS_synchronization2");
Expand Down
4 changes: 4 additions & 0 deletions src/vsg/vk/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/vk/Instance.h>
#include <vsg/vk/PhysicalDevice.h>

#include <algorithm>
#include <cstring>
#include <set>

using namespace vsg;
Expand Down Expand Up @@ -134,6 +136,8 @@ Instance::Instance(Names instanceExtensions, Names layers, uint32_t vulkanApiVer
{
throw Exception{"Error: vsg::Instance::create(...) failed to create VkInstance.", result};
}

_extensions = InstanceExtensions::create(this);
}

Instance::~Instance()
Expand Down
40 changes: 40 additions & 0 deletions src/vsg/vk/InstanceExtensions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* <editor-fold desc="MIT License">

Copyright(c) 2018 Robert Osfield

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

</editor-fold> */

#include <vsg/core/Exception.h>
#include <vsg/io/Logger.h>
#include <vsg/io/Options.h>
#include <vsg/vk/Instance.h>
#include <vsg/vk/InstanceExtensions.h>
#include <vsg/vk/PhysicalDevice.h>

#include <algorithm>
#include <cstring>
#include <set>

using namespace vsg;

InstanceExtensions::InstanceExtensions(Instance* instance)
{
// VK_EXT_debug_utils
instance->getProcAddr(vkSetDebugUtilsObjectNameEXT, "vkSetDebugUtilsObjectNameEXT");
instance->getProcAddr(vkSetDebugUtilsObjectTagEXT, "vkSetDebugUtilsObjectTagEXT");
instance->getProcAddr(vkQueueBeginDebugUtilsLabelEXT, "vkQueueBeginDebugUtilsLabelEXT");
instance->getProcAddr(vkQueueEndDebugUtilsLabelEXT, "vkQueueEndDebugUtilsLabelEXT");
instance->getProcAddr(vkQueueInsertDebugUtilsLabelEXT, "vkQueueInsertDebugUtilsLabelEXT");
instance->getProcAddr(vkCmdBeginDebugUtilsLabelEXT, "vkCmdBeginDebugUtilsLabelEXT");
instance->getProcAddr(vkCmdEndDebugUtilsLabelEXT, "vkCmdEndDebugUtilsLabelEXT");
instance->getProcAddr(vkCmdInsertDebugUtilsLabelEXT, "vkCmdInsertDebugUtilsLabelEXT");
instance->getProcAddr(vkCreateDebugUtilsMessengerEXT, "vkCreateDebugUtilsMessengerEXT");
instance->getProcAddr(vkDestroyDebugUtilsMessengerEXT, "vkDestroyDebugUtilsMessengerEXT");
instance->getProcAddr(vkSubmitDebugUtilsMessageEXT, "vkSubmitDebugUtilsMessageEXT");
}