Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions framework/core/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ inline Instance<bindingType>::Instance(std::string const
.enabledExtensionCount = static_cast<uint32_t>(enabled_extensions_cstr.size()),
.ppEnabledExtensionNames = enabled_extensions_cstr.data()};

vkb::StructureChainBuilder<vkb::BindingType::Cpp, vk::InstanceCreateInfo> scb;
scb.set_anchor_struct(create_info);
vkb::StructureChainBuilderCpp<vk::InstanceCreateInfo> scb(create_info);
if constexpr (bindingType == vkb::BindingType::Cpp)
{
extend_instance_create_info(scb);
Expand Down
44 changes: 10 additions & 34 deletions framework/structure_chain_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ namespace vkb
template <vkb::BindingType bindingType, typename AnchorStructType>
class StructureChainBuilder
{
static_assert((offsetof(AnchorStructType, sType) == 0) && (offsetof(AnchorStructType, pNext) == sizeof(void *)));

public:
StructureChainBuilder();
StructureChainBuilder(AnchorStructType const &anchor_struct);

template <typename T>
T &add_chain_data(T const &data_to_add = {}); // Adds data to the structure chain builder that is not part of the structure chain itself, but is used by the
Expand All @@ -38,14 +40,11 @@ class StructureChainBuilder
template <typename StructType>
StructType const *get_struct(size_t skip = 0) const;

void set_anchor_struct(AnchorStructType const &anchor_struct);

private:
template <typename StructType>
StructType &add_struct_impl(StructType const &struct_to_add);
template <typename StructType>
StructType const *get_struct_impl(size_t skip) const;
void set_anchor_struct_impl(AnchorStructType const &anchor_struct);

private:
std::vector<std::unique_ptr<std::any>> structure_chain;
Expand All @@ -59,18 +58,17 @@ template <typename AnchorStructType>
using StructureChainBuilderCpp = StructureChainBuilder<vkb::BindingType::Cpp, AnchorStructType>;

template <vkb::BindingType bindingType, typename AnchorStructType>
template <typename T>
T &StructureChainBuilder<bindingType, AnchorStructType>::add_chain_data(T const &data_to_add)
inline StructureChainBuilder<bindingType, AnchorStructType>::StructureChainBuilder(AnchorStructType const &anchor_struct)
{
chain_data.push_back(std::make_unique<std::any>(std::make_any<T>(data_to_add)));
return *std::any_cast<T>(chain_data.back().get());
structure_chain.push_back(std::make_unique<std::any>(std::make_any<AnchorStructType>(anchor_struct)));
}

template <vkb::BindingType bindingType, typename AnchorStructType>
inline StructureChainBuilder<bindingType, AnchorStructType>::StructureChainBuilder()
template <typename T>
inline T &StructureChainBuilder<bindingType, AnchorStructType>::add_chain_data(T const &data_to_add)
{
static_assert((offsetof(AnchorStructType, sType) == 0) && (offsetof(AnchorStructType, pNext) == sizeof(void *)));
structure_chain.push_back(std::make_unique<std::any>(std::make_any<AnchorStructType>()));
chain_data.push_back(std::make_unique<std::any>(std::make_any<T>(data_to_add)));
return *std::any_cast<T>(chain_data.back().get());
}

template <vkb::BindingType bindingType, typename AnchorStructType>
Expand Down Expand Up @@ -115,7 +113,7 @@ inline StructType const *StructureChainBuilder<bindingType, AnchorStructType>::g
}
else
{
return reinterpret_cast<StructType const *>(get_struct_impl<vk::CppType<StructType>::Type>(skip));
return reinterpret_cast<StructType const *>(get_struct_impl<typename vk::CppType<StructType>::Type>(skip));
}
}

Expand All @@ -137,26 +135,4 @@ inline StructType const *StructureChainBuilder<bindingType, AnchorStructType>::g
return (it != structure_chain.end()) ? std::any_cast<StructType>(it->get()) : nullptr;
}

template <vkb::BindingType bindingType, typename AnchorStructType>
inline void StructureChainBuilder<bindingType, AnchorStructType>::set_anchor_struct(AnchorStructType const &anchor_struct)
{
if constexpr (bindingType == vkb::BindingType::Cpp)
{
set_anchor_struct_impl(anchor_struct);
}
else
{
return reinterpret_cast<StructureChainBuilder<vkb::BindingType::Cpp, typename vk::CppType<AnchorStructType>::Type> *>(this)->add_anchor_struct(
reinterpret_cast<typename vk::CppType<AnchorStructType>::Type const &>(anchor_struct));
}
}

template <vkb::BindingType bindingType, typename AnchorStructType>
inline void StructureChainBuilder<bindingType, AnchorStructType>::set_anchor_struct_impl(AnchorStructType const &anchor_struct)
{
void const *pNext = std::any_cast<AnchorStructType>(structure_chain.front().get())->pNext;
*std::any_cast<AnchorStructType>(structure_chain.front().get()) = anchor_struct;
std::any_cast<AnchorStructType>(structure_chain.front().get())->pNext = pNext;
}

} // namespace vkb
112 changes: 36 additions & 76 deletions framework/vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ class VulkanSample : public vkb::Application
*/
virtual void draw_renderpass(vkb::core::CommandBuffer<bindingType> &command_buffer, vkb::rendering::RenderTarget<bindingType> &render_target);

virtual void extend_instance_create_info(vkb::StructureChainBuilder<bindingType, InstanceCreateInfoType> &create_info) const;
virtual uint32_t get_api_version() const;
virtual DebugReportCallbackCreateInfoType const *get_debug_report_callback_create_info() const;
virtual DebugUtilsMessengerCreateInfoType const *get_debug_utils_messenger_create_info() const;
virtual InstanceCreateFlagsType get_instance_create_flags(std::vector<std::string> const &enabled_extensions) const;
virtual void extend_instance_create_info(vkb::StructureChainBuilder<bindingType, InstanceCreateInfoType> &scb) const;
virtual uint32_t get_api_version() const;
virtual InstanceCreateFlagsType get_instance_create_flags(std::vector<std::string> const &enabled_extensions) const;

/**
* @brief Override this to customise the creation of the swapchain and render_context
Expand Down Expand Up @@ -340,6 +338,11 @@ class VulkanSample : public vkb::Application
void request_layer_settings_impl(std::vector<vk::LayerSettingEXT> &requested_layer_settings, vkb::StructureChainBuilderCpp<vk::InstanceCreateInfo> &scb) const;
static void set_viewport_and_scissor_impl(vkb::core::CommandBufferCpp const &command_buffer, vk::Extent2D const &extent);

#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
Comment thread
SaschaWillems marked this conversation as resolved.
vk::DebugReportCallbackCreateInfoEXT const &get_debug_report_callback_create_info() const;
vk::DebugUtilsMessengerCreateInfoEXT const &get_debug_utils_messenger_create_info() const;
#endif

/**
* @brief Get sample-specific device extensions.
*
Expand Down Expand Up @@ -780,16 +783,11 @@ inline void VulkanSample<bindingType>::extend_instance_create_info_impl(vkb::Str
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
if (contains(create_info->enabledExtensionCount, create_info->ppEnabledExtensionNames, VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
{
vk::DebugUtilsMessengerCreateInfoEXT debug_utils_messenger_create_info{.messageSeverity = vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning,
.messageType = vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance,
.pfnUserCallback = vkb::core::debug_utils_messenger_callback};
scb.add_struct(debug_utils_messenger_create_info);
scb.add_struct(get_debug_utils_messenger_create_info());
}
else if (contains(create_info->enabledExtensionCount, create_info->ppEnabledExtensionNames, VK_EXT_DEBUG_REPORT_EXTENSION_NAME))
{
vk::DebugReportCallbackCreateInfoEXT debug_report_callback_create_info{.flags = vk::DebugReportFlagBitsEXT::eError | vk::DebugReportFlagBitsEXT::eWarning | vk::DebugReportFlagBitsEXT::ePerformanceWarning,
.pfnCallback = vkb::core::debug_callback};
scb.add_struct(debug_report_callback_create_info);
scb.add_struct(get_debug_report_callback_create_info());
}
#endif

Expand Down Expand Up @@ -841,45 +839,6 @@ inline uint32_t VulkanSample<bindingType>::get_api_version() const
return VK_API_VERSION_1_1;
}

template <vkb::BindingType bindingType>
inline typename VulkanSample<bindingType>::DebugReportCallbackCreateInfoType const *VulkanSample<bindingType>::get_debug_report_callback_create_info() const
{
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
static vk::DebugReportCallbackCreateInfoEXT debug_report_callback_create_info{.flags = vk::DebugReportFlagBitsEXT::eError | vk::DebugReportFlagBitsEXT::eWarning | vk::DebugReportFlagBitsEXT::ePerformanceWarning,
.pfnCallback = vkb::core::debug_callback};
if constexpr (bindingType == vkb::BindingType::Cpp)
{
return &debug_report_callback_create_info;
}
else
{
return reinterpret_cast<VkDebugReportCallbackCreateInfoEXT *>(&debug_report_callback_create_info);
}
#else
return nullptr;
#endif
}

template <vkb::BindingType bindingType>
inline typename VulkanSample<bindingType>::DebugUtilsMessengerCreateInfoType const *VulkanSample<bindingType>::get_debug_utils_messenger_create_info() const
{
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
static vk::DebugUtilsMessengerCreateInfoEXT debug_utils_messenger_create_info{.messageSeverity = vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning,
.messageType = vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance,
.pfnUserCallback = vkb::core::debug_utils_messenger_callback};
if constexpr (bindingType == vkb::BindingType::Cpp)
{
return &debug_utils_messenger_create_info;
}
else
{
return reinterpret_cast<VkDebugUtilsMessengerCreateInfoEXT *>(&debug_utils_messenger_create_info);
}
#else
return nullptr;
#endif
}

template <vkb::BindingType bindingType>
inline typename VulkanSample<bindingType>::InstanceCreateFlagsType VulkanSample<bindingType>::get_instance_create_flags(std::vector<std::string> const &enabled_extensions) const
{
Expand Down Expand Up @@ -933,6 +892,27 @@ inline vkb::core::Device<bindingType> &VulkanSample<bindingType>::get_device()
}
}

#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
template <vkb::BindingType bindingType>
inline vk::DebugReportCallbackCreateInfoEXT const &VulkanSample<bindingType>::get_debug_report_callback_create_info() const
{
static vk::DebugReportCallbackCreateInfoEXT debug_report_callback_create_info =
{.flags = vk::DebugReportFlagBitsEXT::eError | vk::DebugReportFlagBitsEXT::eWarning | vk::DebugReportFlagBitsEXT::ePerformanceWarning,
.pfnCallback = vkb::core::debug_callback};
return debug_report_callback_create_info;
}

template <vkb::BindingType bindingType>
inline vk::DebugUtilsMessengerCreateInfoEXT const &VulkanSample<bindingType>::get_debug_utils_messenger_create_info() const
{
static vk::DebugUtilsMessengerCreateInfoEXT debug_utils_messenger_create_info =
{.messageSeverity = vk::DebugUtilsMessageSeverityFlagBitsEXT::eError | vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning,
.messageType = vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance,
.pfnUserCallback = vkb::core::debug_utils_messenger_callback};
return debug_utils_messenger_create_info;
}
#endif

template <vkb::BindingType bindingType>
inline std::unordered_map<const char *, bool> const &VulkanSample<bindingType>::get_device_extensions() const
{
Expand Down Expand Up @@ -1250,37 +1230,17 @@ inline bool VulkanSample<bindingType>::prepare(const ApplicationOptions &options
instance.reset(reinterpret_cast<vkb::core::InstanceCpp *>(create_instance().release()));
}

// initialize debug utils or report callback based on enabled extensions, if any
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
// initialize debug utils or report callback based on enabled extensions
if (instance->is_extension_enabled(VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
{
auto const *debug_utils_messenger_create_info = get_debug_utils_messenger_create_info();
if (debug_utils_messenger_create_info)
{
if constexpr (bindingType == BindingType::Cpp)
{
debug_utils_messenger = instance->get_handle().createDebugUtilsMessengerEXT(*debug_utils_messenger_create_info);
}
else
{
debug_utils_messenger = instance->get_handle().createDebugUtilsMessengerEXT(*reinterpret_cast<vk::DebugUtilsMessengerCreateInfoEXT const *>(debug_utils_messenger_create_info));
}
}
debug_utils_messenger = instance->get_handle().createDebugUtilsMessengerEXT(get_debug_utils_messenger_create_info());
}
else if (instance->is_extension_enabled(VK_EXT_DEBUG_REPORT_EXTENSION_NAME))
{
auto const *debug_report_callback_create_info = get_debug_report_callback_create_info();
if (debug_report_callback_create_info)
{
if constexpr (bindingType == BindingType::Cpp)
{
debug_report_callback = instance->get_handle().createDebugReportCallbackEXT(*debug_report_callback_create_info);
}
else
{
debug_report_callback = instance->get_handle().createDebugReportCallbackEXT(*reinterpret_cast<vk::DebugReportCallbackCreateInfoEXT const *>(debug_report_callback_create_info));
}
}
debug_report_callback = instance->get_handle().createDebugReportCallbackEXT(get_debug_report_callback_create_info());
}
#endif

// Getting a valid vulkan surface from the platform
surface = static_cast<vk::SurfaceKHR>(window->create_surface(reinterpret_cast<vkb::core::InstanceC &>(*instance)));
Expand Down
37 changes: 21 additions & 16 deletions samples/extensions/shader_debugprintf/shader_debugprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ ShaderDebugPrintf::~ShaderDebugPrintf()
vkDestroyDescriptorSetLayout(get_device().get_handle(), descriptor_set_layout, nullptr);

vkDestroySampler(get_device().get_handle(), textures.skysphere.sampler, nullptr);

vkDestroyDebugUtilsMessengerEXT(get_instance().get_handle(), debug_utils_messenger, nullptr);
}
}

Expand Down Expand Up @@ -440,6 +442,12 @@ bool ShaderDebugPrintf::prepare(const vkb::ApplicationOptions &options)
return false;
}

// Register a sample specific debug utils callback in addition to the one registered by the base class
if (get_instance().is_extension_enabled(VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
{
vkCreateDebugUtilsMessengerEXT(get_instance().get_handle(), &get_debug_utils_messenger_create_info(), nullptr, &debug_utils_messenger);
}

camera.type = vkb::CameraType::LookAt;
camera.set_position(glm::vec3(0.0f, 0.0f, -6.0f));
camera.set_rotation(glm::vec3(0.0f, 180.0f, 0.0f));
Expand All @@ -458,27 +466,24 @@ bool ShaderDebugPrintf::prepare(const vkb::ApplicationOptions &options)
return true;
}

void ShaderDebugPrintf::extend_instance_create_info(vkb::StructureChainBuilderC<VkInstanceCreateInfo> &scb) const
VkDebugUtilsMessengerCreateInfoEXT const &ShaderDebugPrintf::get_debug_utils_messenger_create_info() const
{
ApiVulkanSample::extend_instance_create_info(scb);

// Register a sample specific debug utils callback in addition to the one registered by the base class
VkDebugUtilsMessengerCreateInfoEXT debug_utils_messenger_create_info{.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT,
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT,
.pfnUserCallback = debug_utils_message_callback};
scb.add_struct(debug_utils_messenger_create_info);
static VkDebugUtilsMessengerCreateInfoEXT debug_utils_messenger_create_info =
{.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
.pNext = nullptr,
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT,
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT,
.pfnUserCallback = debug_utils_message_callback,
.pUserData = nullptr};
return debug_utils_messenger_create_info;
}

VkDebugUtilsMessengerCreateInfoEXT const *ShaderDebugPrintf::get_debug_utils_messenger_create_info() const
void ShaderDebugPrintf::extend_instance_create_info(vkb::StructureChainBuilderC<VkInstanceCreateInfo> &scb) const
{
ApiVulkanSample::extend_instance_create_info(scb);

// Register a sample specific debug utils callback in addition to the one registered by the base class
static VkDebugUtilsMessengerCreateInfoEXT local_debug_utils_messenger_create_info{.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
.pNext = ApiVulkanSample::get_debug_utils_messenger_create_info(),
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT,
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT,
.pfnUserCallback = debug_utils_message_callback};
return &local_debug_utils_messenger_create_info;
scb.add_struct(get_debug_utils_messenger_create_info());
Comment thread
asuessenbach marked this conversation as resolved.
}

void ShaderDebugPrintf::render(float delta_time)
Expand Down
Loading
Loading