11/*
22** Copyright (c) 2018-2020 Valve Corporation
3- ** Copyright (c) 2018-2020 LunarG, Inc.
3+ ** Copyright (c) 2018-2023 LunarG, Inc.
44**
55** Permission is hereby granted, free of charge, to any person obtaining a
66** copy of this software and associated documentation files (the "Software"),
3434
3535#include " vulkan/vk_layer.h"
3636
37+ #include < array>
3738#include < cstring>
3839#include < mutex>
3940#include < string>
4041#include < unordered_map>
42+ #include < unordered_set>
4143#include < vector>
4244
4345GFXRECON_BEGIN_NAMESPACE (gfxrecon)
@@ -52,7 +54,16 @@ const VkLayerProperties kLayerProps = {
5254 GFXRECON_PROJECT_VERSION_DESIGNATION
5355};
5456
55- const std::vector<VkExtensionProperties> kDeviceExtensionProps = { VkExtensionProperties{ " VK_EXT_tooling_info" , 1 } };
57+ const std::array<VkExtensionProperties, 2 > kDeviceExtensionProps = {
58+ VkExtensionProperties{ " VK_EXT_tooling_info" , 1 },
59+ VkExtensionProperties{ VK_EXT_DEBUG_MARKER_EXTENSION_NAME, VK_EXT_DEBUG_MARKER_SPEC_VERSION }
60+ };
61+
62+ const std::unordered_set<std::string> kProvidedDeviceFunctions = { " vkCmdDebugMarkerBeginEXT" ,
63+ " vkCmdDebugMarkerEndEXT" ,
64+ " vkCmdDebugMarkerInsertEXT" ,
65+ " vkDebugMarkerSetObjectNameEXT" ,
66+ " vkDebugMarkerSetObjectTagEXT" };
5667
5768// / An alphabetical list of device extensions which we do not report upstream if
5869// / other layers or ICDs expose them to us.
@@ -301,10 +312,10 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, cons
301312 {
302313 result = table->GetDeviceProcAddr (device, pName);
303314
304- if (result != nullptr )
315+ if (result != nullptr || ( kProvidedDeviceFunctions . find (pName) != kProvidedDeviceFunctions . end ()) )
305316 {
306317 // Only check for a layer implementation of the requested function if it is available from the next
307- // level.
318+ // level or if we are providing the implementation ourselves .
308319 const auto entry = func_table.find (pName);
309320 if (entry != func_table.end ())
310321 {
@@ -390,31 +401,53 @@ VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevi
390401 return result;
391402 }
392403
393- std::vector<VkExtensionProperties> downstream_properties (downstream_property_count);
404+ std::vector<VkExtensionProperties> device_extension_properties (downstream_property_count);
394405 result = instance_table->EnumerateDeviceExtensionProperties (
395- physicalDevice, pLayerName, &downstream_property_count, downstream_properties .data ());
406+ physicalDevice, pLayerName, &downstream_property_count, device_extension_properties .data ());
396407 if (result != VK_SUCCESS)
397408 {
398409 return result;
399410 }
400411
401- remove_extensions (downstream_properties ,
412+ remove_extensions (device_extension_properties ,
402413 kUnsupportedDeviceExtensions ,
403414 std::end (kUnsupportedDeviceExtensions ) - std::begin (kUnsupportedDeviceExtensions ));
404415
416+ // Append the extensions we provide in the list to the caller if they aren't already provided downstream.
417+ if (pLayerName == nullptr )
418+ {
419+ for (auto & provided_prop : kDeviceExtensionProps )
420+ {
421+ bool append_provided_prop =
422+ std::find_if (device_extension_properties.begin (),
423+ device_extension_properties.end (),
424+ [&provided_prop](const VkExtensionProperties& downstream_prop) {
425+ return util::platform::StringCompare (provided_prop.extensionName ,
426+ downstream_prop.extensionName ,
427+ VK_MAX_EXTENSION_NAME_SIZE) == 0 ;
428+ }) == device_extension_properties.end ();
429+ if (append_provided_prop)
430+ {
431+ device_extension_properties.push_back (provided_prop);
432+ }
433+ }
434+ }
435+
405436 // Output the reduced count or the reduced extension list:
406437 if (pProperties == nullptr )
407438 {
408- *pPropertyCount = static_cast <uint32_t >(downstream_properties .size ());
439+ *pPropertyCount = static_cast <uint32_t >(device_extension_properties .size ());
409440 }
410441 else
411442 {
412- if (*pPropertyCount < static_cast <uint32_t >(downstream_properties .size ()))
443+ if (*pPropertyCount < static_cast <uint32_t >(device_extension_properties .size ()))
413444 {
414445 result = VK_INCOMPLETE;
415446 }
416- *pPropertyCount = std::min (*pPropertyCount, static_cast <uint32_t >(downstream_properties.size ()));
417- std::copy (downstream_properties.begin (), downstream_properties.begin () + *pPropertyCount, pProperties);
447+ *pPropertyCount = std::min (*pPropertyCount, static_cast <uint32_t >(device_extension_properties.size ()));
448+ std::copy (device_extension_properties.begin (),
449+ device_extension_properties.begin () + *pPropertyCount,
450+ pProperties);
418451 }
419452 }
420453
0 commit comments