Add test for vk::Flags. (#1502)

This commit is contained in:
Andreas Süßenbach 2023-02-13 13:36:43 +01:00 committed by GitHub
parent ab08f20c01
commit 52881a3879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 138 additions and 0 deletions

View File

@ -55,6 +55,7 @@ add_subdirectory(DispatchLoaderDynamic)
add_subdirectory(DispatchLoaderDynamicSharedLibrary)
add_subdirectory(DispatchLoaderDynamicSharedLibraryClient)
add_subdirectory(DispatchLoaderStatic)
add_subdirectory(Flags)
add_subdirectory(FormatTraits)
add_subdirectory(Hash)
add_subdirectory(NoExceptions)

View File

@ -0,0 +1,35 @@
# Copyright(c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.2)
project(Flags)
set(HEADERS
)
set(SOURCES
Flags.cpp
)
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES})
add_executable(Flags
${HEADERS}
${SOURCES}
)
set_target_properties(Flags PROPERTIES FOLDER "Tests")
target_link_libraries(Flags PRIVATE utils)

102
tests/Flags/Flags.cpp Normal file
View File

@ -0,0 +1,102 @@
// Copyright(c) 2023, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// VulkanHpp Samples : Flags
// Compile test on using vk::Flags
// for test purposes, define this to allow access to Flags::m_mask
// You should not use that in production code!!
#define VULKAN_HPP_FLAGS_MASK_TYPE_AS_PUBLIC
// in this test, we ignore some warnings
// You should not do that in production code !!
#if defined( __GNUC__ )
# pragma GCC diagnostic ignored "-Wunused-variable"
#else
// unknow compiler... just ignore the warnings for yourselves ;)
#endif
#include <vulkan/vulkan.hpp>
int main( int /*argc*/, char ** /*argv*/ )
{
vk::MemoryHeapFlags mhf0;
assert( mhf0.m_mask == 0 );
vk::MemoryHeapFlags mhf1( vk::MemoryHeapFlagBits::eDeviceLocal );
assert( mhf1.m_mask == VK_MEMORY_HEAP_DEVICE_LOCAL_BIT );
vk::MemoryHeapFlags mhf2( mhf1 );
assert( mhf2.m_mask == VK_MEMORY_HEAP_DEVICE_LOCAL_BIT );
VkMemoryHeapFlags vkmhf = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT | VK_MEMORY_HEAP_MULTI_INSTANCE_BIT;
vk::MemoryHeapFlags mhf3( vkmhf );
assert( mhf3.m_mask == ( VK_MEMORY_HEAP_DEVICE_LOCAL_BIT | VK_MEMORY_HEAP_MULTI_INSTANCE_BIT ) );
// error
// vk::MemoryHeapFlags mhf4( vk::MemoryHeapFlagBits::eDeviceLocal | vk::ImageAspectFlagBits::eDepth );
assert( mhf0 < mhf1 );
assert( !( mhf1 < mhf2 ) );
assert( mhf0 <= mhf1 );
assert( mhf1 <= mhf2 );
assert( !( mhf3 <= mhf2 ) );
assert( mhf1 > mhf0 );
assert( !( mhf2 > mhf1 ) );
assert( mhf1 >= mhf0 );
assert( mhf2 >= mhf1 );
assert( !( mhf2 >= mhf3 ) );
assert( !( mhf0 == mhf1 ) );
assert( mhf1 == mhf2 );
assert( mhf0 != mhf1 );
assert( !( mhf1 != mhf2 ) );
assert( !mhf0 );
assert( !!mhf1 );
assert( mhf1 & vk::MemoryHeapFlagBits::eDeviceLocal );
assert( !( mhf0 & vk::MemoryHeapFlagBits::eDeviceLocal ) );
assert( ( mhf0 | vk::MemoryHeapFlagBits::eDeviceLocal ) == vk::MemoryHeapFlagBits::eDeviceLocal );
assert( ( mhf1 | vk::MemoryHeapFlagBits::eDeviceLocal ) == vk::MemoryHeapFlagBits::eDeviceLocal );
assert( ( mhf0 ^ mhf1 ) == mhf1 );
assert( ( mhf1 ^ mhf2 ) == mhf0 );
vk::MemoryHeapFlags mhf4( ~mhf0 );
assert( mhf4 == ( vk::MemoryHeapFlagBits::eDeviceLocal | vk::MemoryHeapFlagBits::eMultiInstance ) );
mhf0 = mhf1;
assert( mhf0 == mhf1 );
mhf0 |= vk::MemoryHeapFlagBits::eMultiInstance;
assert( mhf0 & vk::MemoryHeapFlagBits::eMultiInstance );
mhf0 &= vk::MemoryHeapFlagBits::eDeviceLocal;
assert( mhf0 & vk::MemoryHeapFlagBits::eDeviceLocal );
mhf0 ^= mhf3;
assert( mhf0 == ( vk::MemoryHeapFlagBits::eMultiInstance ) );
assert( mhf0 );
vkmhf = static_cast<VkMemoryHeapFlags>(mhf0);
return 0;
}