Vulkan: Use ityp::bitset for Instance/DeviceExtSet

ityp::bitset allows the creation of a bitset indexed by enums. Use this
instead of our custom wrapper around bitset that only supports .Set and
.Has.

Bug: dawn:635
Change-Id: I6680feb9b1741648d974cf1cef48cb1863aa20af
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/38103
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2021-01-21 12:12:59 +00:00 committed by Commit Bot service account
parent ef869c2d01
commit f091fb71f7
5 changed files with 36 additions and 60 deletions

View File

@ -240,8 +240,8 @@ namespace dawn_native { namespace vulkan {
usedKnobs.extensions = extensionsToRequest; usedKnobs.extensions = extensionsToRequest;
std::vector<const char*> extensionNames; std::vector<const char*> extensionNames;
for (uint32_t ext : IterateBitSet(extensionsToRequest.extensionBitSet)) { for (InstanceExt ext : IterateBitSet(extensionsToRequest)) {
const InstanceExtInfo& info = GetInstanceExtInfo(static_cast<InstanceExt>(ext)); const InstanceExtInfo& info = GetInstanceExtInfo(ext);
if (info.versionPromoted > mGlobalInfo.apiVersion) { if (info.versionPromoted > mGlobalInfo.apiVersion) {
extensionNames.push_back(info.name); extensionNames.push_back(info.name);

View File

@ -279,8 +279,8 @@ namespace dawn_native { namespace vulkan {
// However only request the extensions that haven't been promoted in the device's apiVersion // However only request the extensions that haven't been promoted in the device's apiVersion
std::vector<const char*> extensionNames; std::vector<const char*> extensionNames;
for (uint32_t ext : IterateBitSet(usedKnobs.extensions.extensionBitSet)) { for (DeviceExt ext : IterateBitSet(usedKnobs.extensions)) {
const DeviceExtInfo& info = GetDeviceExtInfo(static_cast<DeviceExt>(ext)); const DeviceExtInfo& info = GetDeviceExtInfo(ext);
if (info.versionPromoted > mDeviceInfo.properties.apiVersion) { if (info.versionPromoted > mDeviceInfo.properties.apiVersion) {
extensionNames.push_back(info.name); extensionNames.push_back(info.name);

View File

@ -51,14 +51,6 @@ namespace dawn_native { namespace vulkan {
// //
}}; }};
void InstanceExtSet::Set(InstanceExt extension, bool enabled) {
extensionBitSet.set(static_cast<uint32_t>(extension), enabled);
}
bool InstanceExtSet::Has(InstanceExt extension) const {
return extensionBitSet[static_cast<uint32_t>(extension)];
}
const InstanceExtInfo& GetInstanceExtInfo(InstanceExt ext) { const InstanceExtInfo& GetInstanceExtInfo(InstanceExt ext) {
uint32_t index = static_cast<uint32_t>(ext); uint32_t index = static_cast<uint32_t>(ext);
ASSERT(index < sInstanceExtInfos.size()); ASSERT(index < sInstanceExtInfos.size());
@ -84,8 +76,8 @@ namespace dawn_native { namespace vulkan {
InstanceExtSet trimmedSet; InstanceExtSet trimmedSet;
auto HasDep = [&](InstanceExt ext) -> bool { auto HasDep = [&](InstanceExt ext) -> bool {
ASSERT(visitedSet.Has(ext)); ASSERT(visitedSet[ext]);
return trimmedSet.Has(ext); return trimmedSet[ext];
}; };
for (uint32_t i = 0; i < sInstanceExtInfos.size(); i++) { for (uint32_t i = 0; i < sInstanceExtInfos.size(); i++) {
@ -117,8 +109,8 @@ namespace dawn_native { namespace vulkan {
UNREACHABLE(); UNREACHABLE();
} }
trimmedSet.Set(ext, hasDependencies && advertisedExts.Has(ext)); trimmedSet.set(ext, hasDependencies && advertisedExts[ext]);
visitedSet.Set(ext, true); visitedSet.set(ext, true);
} }
return trimmedSet; return trimmedSet;
@ -127,7 +119,7 @@ namespace dawn_native { namespace vulkan {
void MarkPromotedExtensions(InstanceExtSet* extensions, uint32_t version) { void MarkPromotedExtensions(InstanceExtSet* extensions, uint32_t version) {
for (const InstanceExtInfo& info : sInstanceExtInfos) { for (const InstanceExtInfo& info : sInstanceExtInfos) {
if (info.versionPromoted <= version) { if (info.versionPromoted <= version) {
extensions->Set(info.index, true); extensions->set(info.index, true);
} }
} }
} }
@ -167,14 +159,6 @@ namespace dawn_native { namespace vulkan {
// //
}}; }};
void DeviceExtSet::Set(DeviceExt extension, bool enabled) {
extensionBitSet.set(static_cast<uint32_t>(extension), enabled);
}
bool DeviceExtSet::Has(DeviceExt extension) const {
return extensionBitSet[static_cast<uint32_t>(extension)];
}
const DeviceExtInfo& GetDeviceExtInfo(DeviceExt ext) { const DeviceExtInfo& GetDeviceExtInfo(DeviceExt ext) {
uint32_t index = static_cast<uint32_t>(ext); uint32_t index = static_cast<uint32_t>(ext);
ASSERT(index < sDeviceExtInfos.size()); ASSERT(index < sDeviceExtInfos.size());
@ -199,8 +183,8 @@ namespace dawn_native { namespace vulkan {
DeviceExtSet trimmedSet; DeviceExtSet trimmedSet;
auto HasDep = [&](DeviceExt ext) -> bool { auto HasDep = [&](DeviceExt ext) -> bool {
ASSERT(visitedSet.Has(ext)); ASSERT(visitedSet[ext]);
return trimmedSet.Has(ext); return trimmedSet[ext];
}; };
for (uint32_t i = 0; i < sDeviceExtInfos.size(); i++) { for (uint32_t i = 0; i < sDeviceExtInfos.size(); i++) {
@ -222,16 +206,15 @@ namespace dawn_native { namespace vulkan {
// advertises the extension. So if we didn't have this check, we'd risk a calling // advertises the extension. So if we didn't have this check, we'd risk a calling
// a nullptr. // a nullptr.
case DeviceExt::GetPhysicalDeviceProperties2: case DeviceExt::GetPhysicalDeviceProperties2:
hasDependencies = instanceExts.Has(InstanceExt::GetPhysicalDeviceProperties2); hasDependencies = instanceExts[InstanceExt::GetPhysicalDeviceProperties2];
break; break;
case DeviceExt::ExternalMemoryCapabilities: case DeviceExt::ExternalMemoryCapabilities:
hasDependencies = instanceExts.Has(InstanceExt::ExternalMemoryCapabilities) && hasDependencies = instanceExts[InstanceExt::ExternalMemoryCapabilities] &&
HasDep(DeviceExt::GetPhysicalDeviceProperties2); HasDep(DeviceExt::GetPhysicalDeviceProperties2);
break; break;
case DeviceExt::ExternalSemaphoreCapabilities: case DeviceExt::ExternalSemaphoreCapabilities:
hasDependencies = hasDependencies = instanceExts[InstanceExt::ExternalSemaphoreCapabilities] &&
instanceExts.Has(InstanceExt::ExternalSemaphoreCapabilities) && HasDep(DeviceExt::GetPhysicalDeviceProperties2);
HasDep(DeviceExt::GetPhysicalDeviceProperties2);
break; break;
case DeviceExt::ImageDrmFormatModifier: case DeviceExt::ImageDrmFormatModifier:
@ -242,7 +225,7 @@ namespace dawn_native { namespace vulkan {
break; break;
case DeviceExt::Swapchain: case DeviceExt::Swapchain:
hasDependencies = instanceExts.Has(InstanceExt::Surface); hasDependencies = instanceExts[InstanceExt::Surface];
break; break;
case DeviceExt::SamplerYCbCrConversion: case DeviceExt::SamplerYCbCrConversion:
@ -295,8 +278,8 @@ namespace dawn_native { namespace vulkan {
UNREACHABLE(); UNREACHABLE();
} }
trimmedSet.Set(ext, hasDependencies && advertisedExts.Has(ext)); trimmedSet.set(ext, hasDependencies && advertisedExts[ext]);
visitedSet.Set(ext, true); visitedSet.set(ext, true);
} }
return trimmedSet; return trimmedSet;
@ -305,7 +288,7 @@ namespace dawn_native { namespace vulkan {
void MarkPromotedExtensions(DeviceExtSet* extensions, uint32_t version) { void MarkPromotedExtensions(DeviceExtSet* extensions, uint32_t version) {
for (const DeviceExtInfo& info : sDeviceExtInfos) { for (const DeviceExtInfo& info : sDeviceExtInfos) {
if (info.versionPromoted <= version) { if (info.versionPromoted <= version) {
extensions->Set(info.index, true); extensions->set(info.index, true);
} }
} }
} }

View File

@ -15,7 +15,8 @@
#ifndef DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_ #ifndef DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_
#define DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_ #define DAWNNATIVE_VULKAN_VULKANEXTENSIONS_H_
#include <bitset> #include "common/ityp_bitset.h"
#include <unordered_map> #include <unordered_map>
namespace dawn_native { namespace vulkan { namespace dawn_native { namespace vulkan {
@ -43,12 +44,8 @@ namespace dawn_native { namespace vulkan {
EnumCount, EnumCount,
}; };
// A bitset wrapper that is indexed with InstanceExt. // A bitset that is indexed with InstanceExt.
struct InstanceExtSet { using InstanceExtSet = ityp::bitset<InstanceExt, static_cast<uint32_t>(InstanceExt::EnumCount)>;
std::bitset<static_cast<size_t>(InstanceExt::EnumCount)> extensionBitSet;
void Set(InstanceExt extension, bool enabled);
bool Has(InstanceExt extension) const;
};
// Information about a known instance extension. // Information about a known instance extension.
struct InstanceExtInfo { struct InstanceExtInfo {
@ -106,14 +103,10 @@ namespace dawn_native { namespace vulkan {
EnumCount, EnumCount,
}; };
// A bitset wrapper that is indexed with DeviceExt. // A bitset that is indexed with DeviceExt.
struct DeviceExtSet { using DeviceExtSet = ityp::bitset<DeviceExt, static_cast<uint32_t>(DeviceExt::EnumCount)>;
std::bitset<static_cast<size_t>(DeviceExt::EnumCount)> extensionBitSet;
void Set(DeviceExt extension, bool enabled);
bool Has(DeviceExt extension) const;
};
// A bitset wrapper that is indexed with DeviceExt. // Information about a known device extension.
struct DeviceExtInfo { struct DeviceExtInfo {
DeviceExt index; DeviceExt index;
const char* name; const char* name;

View File

@ -52,11 +52,11 @@ namespace dawn_native { namespace vulkan {
const char kLayerNameFuchsiaImagePipeSwapchain[] = "VK_LAYER_FUCHSIA_imagepipe_swapchain"; const char kLayerNameFuchsiaImagePipeSwapchain[] = "VK_LAYER_FUCHSIA_imagepipe_swapchain";
bool VulkanGlobalKnobs::HasExt(InstanceExt ext) const { bool VulkanGlobalKnobs::HasExt(InstanceExt ext) const {
return extensions.Has(ext); return extensions[ext];
} }
bool VulkanDeviceKnobs::HasExt(DeviceExt ext) const { bool VulkanDeviceKnobs::HasExt(DeviceExt ext) const {
return extensions.Has(ext); return extensions[ext];
} }
ResultOrError<VulkanGlobalInfo> GatherGlobalInfo(const Backend& backend) { ResultOrError<VulkanGlobalInfo> GatherGlobalInfo(const Backend& backend) {
@ -124,7 +124,7 @@ namespace dawn_native { namespace vulkan {
for (const VkExtensionProperties& extension : extensionsProperties) { for (const VkExtensionProperties& extension : extensionsProperties) {
auto it = knownExts.find(extension.extensionName); auto it = knownExts.find(extension.extensionName);
if (it != knownExts.end()) { if (it != knownExts.end()) {
info.extensions.Set(it->second, true); info.extensions.set(it->second, true);
} }
} }
@ -141,7 +141,7 @@ namespace dawn_native { namespace vulkan {
auto it = knownExts.find(extension.extensionName); auto it = knownExts.find(extension.extensionName);
if (it != knownExts.end() && if (it != knownExts.end() &&
it->second == InstanceExt::FuchsiaImagePipeSurface) { it->second == InstanceExt::FuchsiaImagePipeSurface) {
info.extensions.Set(InstanceExt::FuchsiaImagePipeSurface, true); info.extensions.set(InstanceExt::FuchsiaImagePipeSurface, true);
} }
} }
} }
@ -240,7 +240,7 @@ namespace dawn_native { namespace vulkan {
for (const VkExtensionProperties& extension : extensionsProperties) { for (const VkExtensionProperties& extension : extensionsProperties) {
auto it = knownExts.find(extension.extensionName); auto it = knownExts.find(extension.extensionName);
if (it != knownExts.end()) { if (it != knownExts.end()) {
info.extensions.Set(it->second, true); info.extensions.set(it->second, true);
} }
} }
@ -262,17 +262,17 @@ namespace dawn_native { namespace vulkan {
properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2; properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
PNextChainBuilder propertiesChain(&properties2); PNextChainBuilder propertiesChain(&properties2);
if (info.extensions.Has(DeviceExt::ShaderFloat16Int8)) { if (info.extensions[DeviceExt::ShaderFloat16Int8]) {
featuresChain.Add(&info.shaderFloat16Int8Features, featuresChain.Add(&info.shaderFloat16Int8Features,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR); VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR);
} }
if (info.extensions.Has(DeviceExt::_16BitStorage)) { if (info.extensions[DeviceExt::_16BitStorage]) {
featuresChain.Add(&info._16BitStorageFeatures, featuresChain.Add(&info._16BitStorageFeatures,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES); VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES);
} }
if (info.extensions.Has(DeviceExt::SubgroupSizeControl)) { if (info.extensions[DeviceExt::SubgroupSizeControl]) {
featuresChain.Add(&info.subgroupSizeControlFeatures, featuresChain.Add(&info.subgroupSizeControlFeatures,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT); VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT);
propertiesChain.Add( propertiesChain.Add(
@ -280,7 +280,7 @@ namespace dawn_native { namespace vulkan {
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT); VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT);
} }
if (info.extensions.Has(DeviceExt::DriverProperties)) { if (info.extensions[DeviceExt::DriverProperties]) {
propertiesChain.Add(&info.driverProperties, propertiesChain.Add(&info.driverProperties,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES); VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES);
} }
@ -291,7 +291,7 @@ namespace dawn_native { namespace vulkan {
// Note that info.properties has already been filled at the start of this function to get // Note that info.properties has already been filled at the start of this function to get
// `apiVersion`. // `apiVersion`.
ASSERT(info.properties.apiVersion != 0); ASSERT(info.properties.apiVersion != 0);
if (info.extensions.Has(DeviceExt::GetPhysicalDeviceProperties2)) { if (info.extensions[DeviceExt::GetPhysicalDeviceProperties2]) {
vkFunctions.GetPhysicalDeviceProperties2(physicalDevice, &properties2); vkFunctions.GetPhysicalDeviceProperties2(physicalDevice, &properties2);
vkFunctions.GetPhysicalDeviceFeatures2(physicalDevice, &features2); vkFunctions.GetPhysicalDeviceFeatures2(physicalDevice, &features2);
info.features = features2.features; info.features = features2.features;