Revert "Cleanup and asserts for VkPhysicalDeviceFeatures2."

This reverts commit 5ac038b778.
This commit is contained in:
Charles Giessen 2021-04-18 14:09:12 -06:00
parent 38d150101b
commit db55cb8f27
2 changed files with 32 additions and 40 deletions

View File

@ -908,6 +908,7 @@ bool supports_features(VkPhysicalDeviceFeatures supported,
if (requested.inheritedQueries && !supported.inheritedQueries) return false;
for(auto i = 0; i < extension_requested.size(); ++i) {
//auto res = extension_requested[i].match(extension_supported[i]);
auto res = GenericFeaturesPNextNode::match(extension_requested[i], extension_supported[i]);
if(!res) return false;
}
@ -1410,38 +1411,28 @@ detail::Result<Device> DeviceBuilder::build() const {
extensions.push_back({ VK_KHR_SWAPCHAIN_EXTENSION_NAME });
bool has_phys_dev_features_2 = false;
bool user_defined_phys_dev_features_2 = false;
std::vector<VkBaseOutStructure*> final_pnext_chain;
VkDeviceCreateInfo device_create_info = {};
#if defined(VK_API_VERSION_1_1)
for(auto& pnext : info.pNext_chain) {
if(pnext->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2) {
user_defined_phys_dev_features_2 = true;
break;
}
}
auto physical_device_extension_features_copy = physical_device.extended_features_chain;
VkPhysicalDeviceFeatures2 local_features2{};
local_features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
if(!user_defined_phys_dev_features_2) {
auto physical_device_extension_features_copy = physical_device.extended_features_chain;
if (physical_device.instance_version >= VK_MAKE_VERSION(1, 1, 0)) {
local_features2.features = physical_device.features;
final_pnext_chain.push_back(reinterpret_cast<VkBaseOutStructure*>(&local_features2));
has_phys_dev_features_2 = true;
for (auto& features_node : physical_device_extension_features_copy) {
for(auto& features_node : physical_device_extension_features_copy) {
final_pnext_chain.push_back(reinterpret_cast<VkBaseOutStructure*>(&features_node));
}
}
}
if(!user_defined_phys_dev_features_2 && !has_phys_dev_features_2) {
device_create_info.pEnabledFeatures = &physical_device.features;
}
#endif
VkDeviceCreateInfo device_create_info = {};
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device_create_info.flags = info.flags;
device_create_info.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());
device_create_info.pQueueCreateInfos = queueCreateInfos.data();
device_create_info.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
device_create_info.ppEnabledExtensionNames = extensions.data();
for(auto& pnext : info.pNext_chain) {
final_pnext_chain.push_back(pnext);
}
@ -1451,16 +1442,20 @@ detail::Result<Device> DeviceBuilder::build() const {
assert(node->sType != VK_STRUCTURE_TYPE_APPLICATION_INFO);
}
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device_create_info.flags = info.flags;
device_create_info.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());
device_create_info.pQueueCreateInfos = queueCreateInfos.data();
device_create_info.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
device_create_info.ppEnabledExtensionNames = extensions.data();
#if defined(VK_API_VERSION_1_1)
// VUID-VkDeviceCreateInfo-pNext-00373 - don't add pEnabledFeatures if the phys_dev_features_2 is present
if (has_phys_dev_features_2) {
device_create_info.pNext = &local_features2;
if(!final_pnext_chain.empty()) {
device_create_info.pNext = final_pnext_chain.front();
local_features2.pNext = final_pnext_chain.front();
}
device_create_info.pEnabledFeatures = nullptr;
} else {
device_create_info.pEnabledFeatures = &physical_device.features;
}
#else
device_create_info.pEnabledFeatures = &physical_device.features;
#endif
Device device;

View File

@ -124,18 +124,18 @@ struct GenericFeaturesPNextNode {
VkStructureType sType = static_cast<VkStructureType>(0);
void* pNext = nullptr;
static const uint32_t field_capacity = 256;
VkBool32 fields[field_capacity];
VkBool32 fields[256];
template <typename T>
void set(T const& features) {
GenericFeaturesPNextNode node;
*reinterpret_cast<T*>(this) = features;
}
static bool match(GenericFeaturesPNextNode const& requested, GenericFeaturesPNextNode const& supported) {
assert(requested.sType == supported.sType &&
"Non-matching sTypes in features nodes!");
for (uint32_t i = 0; i < field_capacity; i++) {
for (uint32_t i = 0; i < (sizeof(fields) / sizeof(VkBool32)); i++) {
if (requested.fields[i] && !supported.fields[i]) return false;
}
return true;
@ -362,7 +362,6 @@ struct PhysicalDevice {
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
VkSurfaceKHR surface = VK_NULL_HANDLE;
// Note that this reflects selected features carried over from required features, not all features the physical device supports.
VkPhysicalDeviceFeatures features{};
VkPhysicalDeviceProperties properties{};
VkPhysicalDeviceMemoryProperties memory_properties{};
@ -451,8 +450,6 @@ class PhysicalDeviceSelector {
PhysicalDeviceSelector& add_required_extension_features(T const& features) {
assert(features.sType != 0 &&
"Features struct sType must be filled with the struct's corresponding VkStructureType enum");
assert(features.sType != VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 &&
"Do not pass VkPhysicalDeviceFeatures2 as a required extension feature structure. An instance of this is managed internally for selection criteria and device creation.");
detail::GenericFeaturesPNextNode node;
node.set(features);
criteria.extended_features_chain.push_back(node);