Skip to content

Commit

Permalink
Provide func ptrs for debug marker cmds in capture
Browse files Browse the repository at this point in the history
Some VR applications use debug markers to identify frame boundaries but
not all VR devices provide support for VK_EXT_debug_marker. With this
change GFXR provides function pointers for the extension's functions
in order to capture the debug marker calls and track VR frames.
  • Loading branch information
davidd-lunarg committed Jul 11, 2023
1 parent e06ae77 commit 0970ba9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions framework/decode/vulkan_feature_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ GFXRECON_BEGIN_NAMESPACE(feature_util)
// no longer there)
std::set<std::string> kIgnorableExtensions = {
VK_EXT_TOOLING_INFO_EXTENSION_NAME,
VK_EXT_DEBUG_MARKER_EXTENSION_NAME,
};

VkResult GetInstanceLayers(PFN_vkEnumerateInstanceLayerProperties instance_layer_proc,
Expand Down
55 changes: 44 additions & 11 deletions layer/trace_layer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2020 LunarG, Inc.
** Copyright (c) 2018-2023 LunarG, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -33,10 +33,12 @@

#include "vulkan/vk_layer.h"

#include <array>
#include <cstring>
#include <mutex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
Expand All @@ -51,7 +53,16 @@ const VkLayerProperties kLayerProps = {
GFXRECON_PROJECT_VERSION_DESIGNATION
};

const std::vector<VkExtensionProperties> kDeviceExtensionProps = { VkExtensionProperties{ "VK_EXT_tooling_info", 1 } };
const std::array<VkExtensionProperties, 2> kDeviceExtensionProps = {
VkExtensionProperties{ "VK_EXT_tooling_info", 1 },
VkExtensionProperties{ VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION }
};

const std::unordered_set<std::string> kProvidedDeviceFunctions = { "vkCmdDebugMarkerBeginEXT",
"vkCmdDebugMarkerEndEXT",
"vkCmdDebugMarkerInsertEXT",
"vkDebugMarkerSetObjectNameEXT",
"vkDebugMarkerSetObjectTagEXT" };

/// An alphabetical list of device extensions which we do not report upstream if
/// other layers or ICDs expose them to us.
Expand Down Expand Up @@ -289,10 +300,10 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, cons
{
result = table->GetDeviceProcAddr(device, pName);

if (result != nullptr)
if (result != nullptr || (kProvidedDeviceFunctions.find(pName) != kProvidedDeviceFunctions.end()))
{
// Only check for a layer implementation of the requested function if it is available from the next
// level.
// level or if we are providing the implementation ourselves.
const auto entry = func_table.find(pName);
if (entry != func_table.end())
{
Expand Down Expand Up @@ -378,31 +389,53 @@ VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevi
return result;
}

std::vector<VkExtensionProperties> downstream_properties(downstream_property_count);
std::vector<VkExtensionProperties> device_extension_properties(downstream_property_count);
result = instance_table->EnumerateDeviceExtensionProperties(
physicalDevice, pLayerName, &downstream_property_count, downstream_properties.data());
physicalDevice, pLayerName, &downstream_property_count, device_extension_properties.data());
if (result != VK_SUCCESS)
{
return result;
}

remove_extensions(downstream_properties,
remove_extensions(device_extension_properties,
kUnsupportedDeviceExtensions,
std::end(kUnsupportedDeviceExtensions) - std::begin(kUnsupportedDeviceExtensions));

// Append the extensions we provide in the list to the caller if they aren't already provided downstream.
if (pLayerName == nullptr)
{
for (auto& provided_prop : kDeviceExtensionProps)
{
bool append_provided_prop =
std::find_if(device_extension_properties.begin(),
device_extension_properties.end(),
[&provided_prop](const VkExtensionProperties& downstream_prop) {
return util::platform::StringCompare(provided_prop.extensionName,
downstream_prop.extensionName,
VK_MAX_EXTENSION_NAME_SIZE) == 0;
}) == device_extension_properties.end();
if (append_provided_prop)
{
device_extension_properties.push_back(provided_prop);
}
}
}

// Output the reduced count or the reduced extension list:
if (pProperties == nullptr)
{
*pPropertyCount = static_cast<uint32_t>(downstream_properties.size());
*pPropertyCount = static_cast<uint32_t>(device_extension_properties.size());
}
else
{
if (*pPropertyCount < static_cast<uint32_t>(downstream_properties.size()))
if (*pPropertyCount < static_cast<uint32_t>(device_extension_properties.size()))
{
result = VK_INCOMPLETE;
}
*pPropertyCount = std::min(*pPropertyCount, static_cast<uint32_t>(downstream_properties.size()));
std::copy(downstream_properties.begin(), downstream_properties.begin() + *pPropertyCount, pProperties);
*pPropertyCount = std::min(*pPropertyCount, static_cast<uint32_t>(device_extension_properties.size()));
std::copy(device_extension_properties.begin(),
device_extension_properties.begin() + *pPropertyCount,
pProperties);
}
}

Expand Down

0 comments on commit 0970ba9

Please sign in to comment.