2020-03-30 10:18:06 +00:00
|
|
|
// Copyright(c) 2018, 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 : Hash
|
|
|
|
// Compile test on using std::hash on handles
|
|
|
|
|
2020-10-20 07:55:19 +00:00
|
|
|
#if defined( _MSC_VER )
|
|
|
|
# pragma warning( disable : 4189 ) // local variable is initialized but not referenced
|
|
|
|
#elif defined( __GNUC__ )
|
|
|
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
|
|
|
#else
|
|
|
|
// unknow compiler... just ignore the warnings for yourselves ;)
|
|
|
|
#endif
|
|
|
|
|
2020-03-30 10:18:06 +00:00
|
|
|
#include "vulkan/vulkan.hpp"
|
2020-04-12 19:49:12 +00:00
|
|
|
|
2020-03-30 10:18:06 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
static char const * AppName = "Hash";
|
|
|
|
static char const * EngineName = "Vulkan.hpp";
|
2020-03-30 10:18:06 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
int main( int /*argc*/, char ** /*argv*/ )
|
2020-03-30 10:18:06 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::ApplicationInfo appInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
|
|
|
vk::UniqueInstance instance = vk::createInstanceUnique( vk::InstanceCreateInfo( {}, &appInfo ) );
|
2020-03-30 10:18:06 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
auto h1 = std::hash<vk::Instance>{}( *instance );
|
|
|
|
auto h2 = std::hash<VkInstance>{}( *instance );
|
|
|
|
assert( h1 == h2 );
|
2020-03-30 10:18:06 +00:00
|
|
|
|
|
|
|
std::unordered_set<vk::Instance> uset;
|
2020-04-12 19:49:12 +00:00
|
|
|
uset.insert( *instance );
|
2020-03-30 10:18:06 +00:00
|
|
|
|
|
|
|
std::unordered_map<vk::Instance, size_t> umap;
|
|
|
|
umap[*instance] = 1;
|
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( vk::SystemError const & err )
|
2020-03-30 10:18:06 +00:00
|
|
|
{
|
|
|
|
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2020-03-30 10:18:06 +00:00
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( ... )
|
2020-03-30 10:18:06 +00:00
|
|
|
{
|
|
|
|
std::cout << "unknown error\n";
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2020-03-30 10:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|