Skip to content
Open
3 changes: 3 additions & 0 deletions include/nbl/video/CVulkanConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class NBL_API2 CVulkanConnection final : public IAPIConnection
inline E_API_TYPE getAPIType() const override {return EAT_VULKAN;}

inline IDebugCallback* getDebugCallback() const override {return m_debugCallback.get();}

inline const core::vector<core::string>& getVulkanProfiles() const { return m_vulkanProfiles; }

bool startCapture() override;
bool endCapture() override;
Expand All @@ -44,6 +46,7 @@ class NBL_API2 CVulkanConnection final : public IAPIConnection
const VkDebugUtilsMessengerEXT m_vkDebugUtilsMessengerEXT;
const std::unique_ptr<CVulkanDebugCallback> m_debugCallback; // this needs to live longer than VkDebugUtilsMessengerEXT handle above
std::atomic_flag flag;
core::vector<core::string> m_vulkanProfiles;
};

}
Expand Down
5 changes: 4 additions & 1 deletion src/nbl/video/CVulkanConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,18 @@ core::smart_refctd_ptr<CVulkanConnection> CVulkanConnection::create(core::smart_

core::smart_refctd_ptr<CVulkanConnection> api(new CVulkanConnection(vk_instance,enabledFeatures,std::move(debugCallback),vk_debugMessenger),core::dont_grab);
api->m_physicalDevices.reserve(vk_physicalDevices.size());
api->m_vulkanProfiles.reserve(vk_physicalDevices.size());
for (auto vk_physicalDevice : vk_physicalDevices)
{
auto device = CVulkanPhysicalDevice::create(core::smart_refctd_ptr(sys),api.get(),api->m_rdoc_api,vk_physicalDevice);
auto& profile = api->m_vulkanProfiles.emplace_back();
auto device = CVulkanPhysicalDevice::create(core::smart_refctd_ptr(sys),api.get(),api->m_rdoc_api,vk_physicalDevice, profile);
if (!device)
{
LOG(api->getDebugCallback()->getLogger(), "Vulkan device %p found but doesn't meet minimum Nabla requirements. Skipping!", system::ILogger::ELL_WARNING, vk_physicalDevice);
continue;
}
api->m_physicalDevices.emplace_back(std::move(device));
// device enumeration
}
#undef LOF

Expand Down
13 changes: 11 additions & 2 deletions src/nbl/video/CVulkanPhysicalDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "nbl/video/CVulkanPhysicalDevice.h"
#include "nbl/video/CVulkanLogicalDevice.h"

#include "nlohmann/json.hpp" // TODO/FIXME: this is probably a mess making, consult someone how to do it better.

namespace nbl::video
{

Expand All @@ -10,7 +12,7 @@ do { \
return nullptr; \
} while(0)

std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart_refctd_ptr<system::ISystem>&& sys, IAPIConnection* const api, renderdoc_api_t* const rdoc, const VkPhysicalDevice vk_physicalDevice)
std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart_refctd_ptr<system::ISystem>&& sys, IAPIConnection* const api, renderdoc_api_t* const rdoc, const VkPhysicalDevice vk_physicalDevice, core::string& profile)
{
system::logger_opt_ptr logger = api->getDebugCallback()->getLogger();

Expand All @@ -25,6 +27,8 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
}
});

using json = nlohmann::json;
json profileObject = { {"$schema", "https://schema.khronos.org/vulkan/profiles-0.8-latest.json"} };

auto& properties = initData.properties;
auto& features = initData.features;
Expand Down Expand Up @@ -263,7 +267,10 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
assert(VK_SUCCESS==res);

for (const auto& vk_extension : vk_extensions)
{
profileObject["capabilities"]["device"]["extensions"][vk_extension.extensionName] = vk_extension.specVersion;
availableFeatureSet.insert(vk_extension.extensionName);
}
}
auto isExtensionSupported = [&availableFeatureSet](const char* name)->bool
{
Expand Down Expand Up @@ -1366,8 +1373,10 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
// bufferUsages.opticalFlowCost = anyFlag(bufferFeatures,VK_FORMAT_FEATURE_2_OPTICAL_FLOW_COST_BIT_NV);
}

profile = profileObject.dump(4); // nicely indented json

success = true;
return std::unique_ptr<CVulkanPhysicalDevice>(new CVulkanPhysicalDevice(std::move(initData),rdoc,vk_physicalDevice,std::move(availableFeatureSet)));
return std::unique_ptr<CVulkanPhysicalDevice>(new CVulkanPhysicalDevice(std::move(initData),rdoc,vk_physicalDevice,std::move(availableFeatureSet),profile));
}

#undef RETURN_NULL_PHYSICAL_DEVICE
Expand Down
9 changes: 6 additions & 3 deletions src/nbl/video/CVulkanPhysicalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ namespace nbl::video
class CVulkanPhysicalDevice final : public IPhysicalDevice
{
public:
static std::unique_ptr<CVulkanPhysicalDevice> create(core::smart_refctd_ptr<system::ISystem>&& sys, IAPIConnection* const api, renderdoc_api_t* const rdoc, const VkPhysicalDevice vk_physicalDevice);
static std::unique_ptr<CVulkanPhysicalDevice> create(core::smart_refctd_ptr<system::ISystem>&& sys, IAPIConnection* const api, renderdoc_api_t* const rdoc, const VkPhysicalDevice vk_physicalDevice, core::string& profile);

inline VkPhysicalDevice getInternalObject() const { return m_vkPhysicalDevice; }

inline E_API_TYPE getAPIType() const override { return EAT_VULKAN; }

inline const core::string& getProfile() const { return m_profile; }

protected:
inline CVulkanPhysicalDevice(IPhysicalDevice::SInitData&& _initData, renderdoc_api_t* const rdoc, const VkPhysicalDevice vk_physicalDevice, core::unordered_set<std::string>&& _extensions)
: IPhysicalDevice(std::move(_initData)), m_rdoc_api(rdoc), m_vkPhysicalDevice(vk_physicalDevice), m_extensions(std::move(_extensions)) {}
inline CVulkanPhysicalDevice(IPhysicalDevice::SInitData&& _initData, renderdoc_api_t* const rdoc, const VkPhysicalDevice vk_physicalDevice, core::unordered_set<std::string>&& _extensions, core::string& profile)
: IPhysicalDevice(std::move(_initData)), m_rdoc_api(rdoc), m_vkPhysicalDevice(vk_physicalDevice), m_extensions(std::move(_extensions)), m_profile(profile) {}

//! This function makes sure requirements of a requested feature is also set to `true` in SPhysicalDeviceFeatures
//! Note that this will only fix what is exposed, some may require extensions not exposed currently, that will happen later on.
Expand Down Expand Up @@ -115,6 +117,7 @@ class CVulkanPhysicalDevice final : public IPhysicalDevice
renderdoc_api_t* const m_rdoc_api;
const VkPhysicalDevice m_vkPhysicalDevice;

core::string& m_profile;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you doing!?

you do realize the vector grows and reallocates ? you need an index into it!

Copy link
Contributor Author

@YasInvolved YasInvolved Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot that it might behave like that. Let me correct that

const core::unordered_set<std::string> m_extensions;
};

Expand Down
Loading