change calls to std::find, std::find_if, and std::find_if_not to functionally identical calls to std::any_of, std::all_of, and std::none_of, when appropriate (#1621)

This commit is contained in:
Andreas Süßenbach
2023-07-13 11:26:01 +02:00
committed by GitHub
parent 069c3b875e
commit 207031caa4
11 changed files with 270 additions and 283 deletions

View File

@@ -109,10 +109,9 @@ bool checkLayers( std::vector<char const *> const & layers, std::vector<vk::Laye
layers.end(),
[&properties]( char const * name )
{
return std::find_if( properties.begin(),
properties.end(),
[&name]( vk::LayerProperties const & property )
{ return strcmp( property.layerName, name ) == 0; } ) != properties.end();
return std::any_of( properties.begin(),
properties.end(),
[&name]( vk::LayerProperties const & property ) { return strcmp( property.layerName, name ) == 0; } );
} );
}

View File

@@ -70,6 +70,7 @@ struct GeometryInstanceData
uint32_t flags : 8; // Instance flags, such as culling
uint64_t accelerationStructureHandle; // Opaque handle of the bottom-level acceleration structure
};
static_assert( sizeof( GeometryInstanceData ) == 64, "GeometryInstanceData structure compiles to incorrect size" );
struct AccelerationStructureData
@@ -198,6 +199,7 @@ struct Material
glm::vec3 diffuse = glm::vec3( 0.7f, 0.7f, 0.7f );
int textureID = -1;
};
const size_t MaterialStride = ( ( sizeof( Material ) + 15 ) / 16 ) * 16;
struct Vertex
@@ -209,6 +211,7 @@ struct Vertex
glm::vec2 texCoord;
int matID;
};
const size_t VertexStride = ( ( sizeof( Vertex ) + 15 ) / 16 ) * 16;
static const std::vector<Vertex> cubeData = {
@@ -695,11 +698,9 @@ int main( int /*argc*/, char ** /*argv*/ )
for ( auto & pd : physicalDevices )
{
std::vector<vk::ExtensionProperties> ep = pd.enumerateDeviceExtensionProperties();
if ( std::find_if( ep.cbegin(),
ep.cend(),
[]( vk::ExtensionProperties const & prop )
{ return strcmp( prop.extensionName, VK_NV_RAY_TRACING_EXTENSION_NAME ) == 0; } ) !=
ep.cend() )
if ( std::any_of( ep.cbegin(),
ep.cend(),
[]( vk::ExtensionProperties const & prop ) { return strcmp( prop.extensionName, VK_NV_RAY_TRACING_EXTENSION_NAME ) == 0; } ) )
{
physicalDevice = pd;
break;
@@ -733,11 +734,11 @@ int main( int /*argc*/, char ** /*argv*/ )
auto supportedFeatures = physicalDevice.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>();
vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice,
graphicsAndPresentQueueFamilyIndex.first,
{ VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
VK_KHR_MAINTENANCE_3_EXTENSION_NAME,
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_NV_RAY_TRACING_EXTENSION_NAME },
{ VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
VK_KHR_MAINTENANCE_3_EXTENSION_NAME,
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_NV_RAY_TRACING_EXTENSION_NAME },
&supportedFeatures.get<vk::PhysicalDeviceFeatures2>().features,
&supportedFeatures.get<vk::PhysicalDeviceDescriptorIndexingFeaturesEXT>() );

View File

@@ -50,12 +50,12 @@ int main( int /*argc*/, char ** /*argv*/ )
{
vk::raii::Context context;
std::vector<vk::ExtensionProperties> instanceExtensionProperties = context.enumerateInstanceExtensionProperties();
bool supportsGetSurfaceCapabilities2 = ( std::find_if( instanceExtensionProperties.begin(),
instanceExtensionProperties.end(),
[]( vk::ExtensionProperties const & ep ) {
return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0;
} ) != instanceExtensionProperties.end() );
std::vector<vk::ExtensionProperties> instanceExtensionProperties = context.enumerateInstanceExtensionProperties();
bool supportsGetSurfaceCapabilities2 =
std::any_of( instanceExtensionProperties.begin(),
instanceExtensionProperties.end(),
[]( vk::ExtensionProperties const & ep ) { return strcmp( ep.extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME ) == 0; } );
std::vector<std::string> extensions = vk::su::getInstanceExtensions();
if ( supportsGetSurfaceCapabilities2 )