11#include < algorithm>
2- #include < array>
32#include < cstdint>
43#include < cstring>
54#include < quark/vk/device/details/device.hpp>
@@ -13,15 +12,6 @@ namespace quark::vk::details {
1312
1413namespace {
1514
16- struct FeatureDesc {
17- Device::Features bit;
18- const char *name;
19- };
20-
21- static constexpr std::array<FeatureDesc, 1 > kFeatureDescs = {{
22- {.bit = Device::Features::TimelineSemaphore, .name = " timelineSemaphore" },
23- }};
24-
2515struct DeviceFeatureChain {
2616 VkPhysicalDeviceFeatures2 features2{};
2717 VkPhysicalDeviceVulkan12Features vk12{};
@@ -46,7 +36,9 @@ struct DeviceFeatureChain {
4636
4737[[nodiscard]] util::Result<DeviceFeatureChain>
4838build_device_feature_chain (VkPhysicalDevice physical_device,
49- const Device::FeatureFlags requested_flags) {
39+ const Device::FeatureFlags required_flags,
40+ const Device::FeatureFlags preferred_flags,
41+ Device::Capabilities &capabilities) {
5042 QUARK_ENSURE (physical_device != VK_NULL_HANDLE,
5143 QUARK_ERR (util::Errc::InvalidArg, " physical_device is null" ));
5244
@@ -58,17 +50,25 @@ build_device_feature_chain(VkPhysicalDevice physical_device,
5850 auto maybe_enable = [&](Device::Features bit, const char *name,
5951 VkBool32 supported_value,
6052 VkBool32 &out_enable) -> util::Status {
61- if (!has_feature (requested_flags, bit)) {
53+ const bool required = has_feature (required_flags, bit);
54+ const bool preferred = has_feature (preferred_flags, bit);
55+ if (!required && !preferred) {
6256 QUARK_OK ();
6357 }
64- QUARK_LOG_INFO (" device feature requested: {} supported={}" , name,
58+ QUARK_LOG_INFO (" device feature requested: {} required={} supported={}" ,
59+ name, required ? " true" : " false" ,
6560 supported_value ? " true" : " false" );
6661
67- QUARK_ENSURE (supported_value == VK_TRUE,
68- QUARK_ERR (util::Errc::Unsupported,
69- " Required device feature unsupported: {}" , name));
62+ if (supported_value != VK_TRUE) {
63+ QUARK_ENSURE (required,
64+ QUARK_ERR (util::Errc::Unsupported,
65+ " Required device feature unsupported: {}" , name));
66+ QUARK_LOG_INFO (" device feature unavailable: {}" , name);
67+ QUARK_OK ();
68+ }
7069
7170 out_enable = VK_TRUE;
71+ capabilities.enabled_features |= static_cast <Device::FeatureFlags>(bit);
7272 QUARK_LOG_INFO (" device feature enabled: {}" , name);
7373 QUARK_OK ();
7474 };
@@ -77,9 +77,13 @@ build_device_feature_chain(VkPhysicalDevice physical_device,
7777 Device::Features::TimelineSemaphore, " timelineSemaphore" ,
7878 supported.vk12 .timelineSemaphore , requested.vk12 .timelineSemaphore ));
7979
80- // TODO: UNCOMMENT TO TEST DEBUG MESSENGER
81- // ITS NOT WORKING FOR make run AND ONLY UBSAN/ASAN RUNS
82- // return supported;
80+ QUARK_TRY_STATUS (maybe_enable (
81+ Device::Features::DynamicRendering, " dynamicRendering" ,
82+ supported.vk13 .dynamicRendering , requested.vk13 .dynamicRendering ));
83+
84+ QUARK_TRY_STATUS (maybe_enable (
85+ Device::Features::Synchronization2, " synchronization2" ,
86+ supported.vk13 .synchronization2 , requested.vk13 .synchronization2 ));
8387
8488 return requested;
8589}
@@ -106,6 +110,11 @@ util::Status Device::create(const Device::CreateInfo &ci) {
106110 graphics_queue_family_index_ = selection.graphics_queue_family_index ;
107111 present_queue_family_index_ = selection.present_queue_family_index ;
108112
113+ VkPhysicalDeviceProperties properties{};
114+ vkGetPhysicalDeviceProperties (physical_device_, &properties);
115+ capabilities_.api_version = properties.apiVersion ;
116+ capabilities_.enabled_features = 0 ;
117+
109118 constexpr float queue_priority{1 .0F };
110119 const std::set<uint32_t > unique_queue_families{graphics_queue_family_index_,
111120 present_queue_family_index_};
@@ -128,7 +137,8 @@ util::Status Device::create(const Device::CreateInfo &ci) {
128137
129138 DeviceFeatureChain feature_chain{};
130139 QUARK_TRY_ASSIGN (feature_chain, build_device_feature_chain (
131- physical_device_, ci.requested_features ));
140+ physical_device_, ci.required_features ,
141+ ci.preferred_features , capabilities_));
132142
133143 VkDeviceCreateInfo create_info{};
134144 create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
@@ -165,6 +175,7 @@ void Device::destroy() noexcept {
165175 graphics_queue_family_index_ = 0 ;
166176 present_queue_family_index_ = 0 ;
167177 alloc_ = nullptr ;
178+ capabilities_ = Capabilities{};
168179}
169180
170181util::Result<Device::DeviceSelection> Device::pick_physical_device_ (
0 commit comments