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
|
|
|
|
|
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"
|
2019-03-05 07:59:40 +00:00
|
|
|
#include <iostream>
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
#define GLM_FORCE_RADIANS
|
2018-08-17 15:47:48 +00:00
|
|
|
#pragma warning(disable:4201) // disable warning C4201: nonstandard extension used: nameless struct/union; needed to get glm/detail/type_vec?.hpp without warnings
|
2018-05-07 12:28:11 +00:00
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
|
|
|
static char const* AppName = "09_InitDescriptorSet";
|
|
|
|
static char const* EngineName = "Vulkan.hpp";
|
|
|
|
|
2019-03-19 14:35:08 +00:00
|
|
|
int main(int /*argc*/, char ** /*argv*/)
|
2018-05-07 12:28:11 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-03-05 07:59:40 +00:00
|
|
|
vk::UniqueInstance instance = vk::su::createInstance(AppName, EngineName);
|
|
|
|
#if !defined(NDEBUG)
|
|
|
|
vk::UniqueDebugReportCallbackEXT debugReportCallback = vk::su::createDebugReportCallback(instance);
|
|
|
|
#endif
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
std::vector<vk::PhysicalDevice> physicalDevices = instance->enumeratePhysicalDevices();
|
|
|
|
assert(!physicalDevices.empty());
|
|
|
|
|
2019-03-05 07:59:40 +00:00
|
|
|
vk::UniqueDevice device = vk::su::createDevice(physicalDevices[0], vk::su::findGraphicsQueueFamilyIndex(physicalDevices[0].getQueueFamilyProperties()));
|
2018-05-07 12:28:11 +00:00
|
|
|
|
2019-03-26 11:24:36 +00:00
|
|
|
vk::su::BufferData uniformBufferData(physicalDevices[0], device, sizeof(glm::mat4x4), vk::BufferUsageFlagBits::eUniformBuffer);
|
2019-04-15 08:18:58 +00:00
|
|
|
vk::su::copyToDevice(device, uniformBufferData.deviceMemory, vk::su::createModelViewProjectionClipMatrix(vk::Extent2D(0, 0)));
|
2019-03-15 09:40:45 +00:00
|
|
|
|
2019-05-21 13:44:52 +00:00
|
|
|
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(device, { {vk::DescriptorType::eUniformBuffer, vk::ShaderStageFlagBits::eVertex} });
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
/* VULKAN_HPP_KEY_START */
|
|
|
|
|
|
|
|
// create a descriptor pool
|
|
|
|
vk::DescriptorPoolSize poolSize(vk::DescriptorType::eUniformBuffer, 1);
|
2019-03-05 07:59:40 +00:00
|
|
|
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize));
|
2018-05-07 12:28:11 +00:00
|
|
|
|
|
|
|
// allocate a descriptor set
|
|
|
|
std::vector<vk::UniqueDescriptorSet> descriptorSets = device->allocateDescriptorSetsUnique(vk::DescriptorSetAllocateInfo(descriptorPool.get(), 1, &descriptorSetLayout.get()));
|
|
|
|
|
2019-03-26 11:24:36 +00:00
|
|
|
vk::DescriptorBufferInfo descriptorBufferInfo(uniformBufferData.buffer.get(), 0, sizeof(glm::mat4x4));
|
2018-05-07 12:28:11 +00:00
|
|
|
device->updateDescriptorSets(vk::WriteDescriptorSet(descriptorSets[0].get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &descriptorBufferInfo), {});
|
|
|
|
|
|
|
|
/* VULKAN_HPP_KEY_END */
|
|
|
|
}
|
|
|
|
catch (vk::SystemError err)
|
|
|
|
{
|
|
|
|
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
catch (std::runtime_error err)
|
|
|
|
{
|
|
|
|
std::cout << "std::runtime_error: " << err.what() << std::endl;
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cout << "unknown error\n";
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|