2019-03-05 07:59:40 +00:00
|
|
|
// Copyright(c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
|
2018-05-07 12:28:11 +00:00
|
|
|
//
|
|
|
|
// 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 : 09_InitDescriptorSet
|
|
|
|
// Initialize a descriptor set
|
|
|
|
|
2020-09-30 10:00:32 +00:00
|
|
|
#if defined( _MSC_VER )
|
|
|
|
# pragma warning( disable : 4201 ) // disable warning C4201: nonstandard extension used: nameless struct/union; needed
|
|
|
|
// to get glm/detail/type_vec?.hpp without warnings
|
|
|
|
#elif defined( __GNUC__ )
|
|
|
|
// don't know how to switch off that warning here
|
|
|
|
#else
|
|
|
|
// unknow compiler... just ignore the warnings for yourselves ;)
|
|
|
|
#endif
|
|
|
|
|
2019-03-26 11:24:36 +00:00
|
|
|
#include "../utils/math.hpp"
|
2019-03-19 14:35:08 +00:00
|
|
|
#include "../utils/utils.hpp"
|
2018-05-07 12:28:11 +00:00
|
|
|
#include "vulkan/vulkan.hpp"
|
2020-04-12 19:49:12 +00:00
|
|
|
|
2019-03-05 07:59:40 +00:00
|
|
|
#include <iostream>
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
#define GLM_FORCE_RADIANS
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
static char const * AppName = "09_InitDescriptorSet";
|
|
|
|
static char const * EngineName = "Vulkan.hpp";
|
2018-05-07 12:28:11 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
int main( int /*argc*/, char ** /*argv*/ )
|
2018-05-07 12:28:11 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::UniqueInstance instance = vk::su::createInstance( AppName, EngineName );
|
|
|
|
#if !defined( NDEBUG )
|
|
|
|
vk::UniqueDebugUtilsMessengerEXT debugUtilsMessenger = vk::su::createDebugUtilsMessenger( instance );
|
2019-03-05 07:59:40 +00:00
|
|
|
#endif
|
2018-05-07 12:28:11 +00:00
|
|
|
|
2019-06-25 07:47:27 +00:00
|
|
|
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
2018-05-07 12:28:11 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::UniqueDevice device = vk::su::createDevice(
|
|
|
|
physicalDevice, vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() ) );
|
2018-05-07 12:28:11 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::su::BufferData uniformBufferData(
|
|
|
|
physicalDevice, device, sizeof( glm::mat4x4 ), vk::BufferUsageFlagBits::eUniformBuffer );
|
|
|
|
vk::su::copyToDevice(
|
|
|
|
device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix( vk::Extent2D( 0, 0 ) ) );
|
2019-03-15 09:40:45 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
|
|
|
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
/* VULKAN_HPP_KEY_START */
|
|
|
|
|
|
|
|
// create a descriptor pool
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
|
|
|
|
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
2020-07-08 08:58:37 +00:00
|
|
|
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
// allocate a descriptor set
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::UniqueDescriptorSet descriptorSet = std::move(
|
2020-07-08 08:58:37 +00:00
|
|
|
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
2020-04-12 19:49:12 +00:00
|
|
|
.front() );
|
2018-05-07 12:28:11 +00:00
|
|
|
|
2020-04-12 19:49:12 +00:00
|
|
|
vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
|
|
|
device->updateDescriptorSets(
|
2020-07-08 08:58:37 +00:00
|
|
|
vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo ),
|
2020-04-12 19:49:12 +00:00
|
|
|
{} );
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
/* VULKAN_HPP_KEY_END */
|
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( vk::SystemError & err )
|
2018-05-07 12:28:11 +00:00
|
|
|
{
|
|
|
|
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2018-05-07 12:28:11 +00:00
|
|
|
}
|
2020-07-08 08:58:37 +00:00
|
|
|
catch ( std::exception & err )
|
2018-05-07 12:28:11 +00:00
|
|
|
{
|
2020-07-08 08:58:37 +00:00
|
|
|
std::cout << "std::exception: " << err.what() << std::endl;
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2018-05-07 12:28:11 +00:00
|
|
|
}
|
2020-04-12 19:49:12 +00:00
|
|
|
catch ( ... )
|
2018-05-07 12:28:11 +00:00
|
|
|
{
|
|
|
|
std::cout << "unknown error\n";
|
2020-04-12 19:49:12 +00:00
|
|
|
exit( -1 );
|
2018-05-07 12:28:11 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|