|
|
@ -1,12 +1,14 @@ |
|
|
|
#include "vulkan/descriptor_pool.hpp" |
|
|
|
#include "vulkan/descriptor_pool.hpp" |
|
|
|
#include "vulkan/instance.hpp" |
|
|
|
#include "vulkan/instance.hpp" |
|
|
|
#include "vulkan/buffer.hpp" |
|
|
|
#include "vulkan/buffer.hpp" |
|
|
|
|
|
|
|
#include "vulkan/image.hpp" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DescriptorPool::DescriptorPool() { |
|
|
|
DescriptorPool::DescriptorPool() { |
|
|
|
VkDescriptorPoolSize poolSizes[] = { |
|
|
|
VkDescriptorPoolSize poolSizes[] = { |
|
|
|
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 20}, |
|
|
|
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 20}, |
|
|
|
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 20} |
|
|
|
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 20}, |
|
|
|
|
|
|
|
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 10} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
VkDescriptorPoolCreateInfo poolInfo {}; |
|
|
|
VkDescriptorPoolCreateInfo poolInfo {}; |
|
|
@ -32,6 +34,8 @@ DescriptorPool::DescriptorPool() { |
|
|
|
addBinding(DescriptorSet::WORLD, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_COMPUTE_BIT); |
|
|
|
addBinding(DescriptorSet::WORLD, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_COMPUTE_BIT); |
|
|
|
// lights
|
|
|
|
// lights
|
|
|
|
addBinding(DescriptorSet::WORLD, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT); |
|
|
|
addBinding(DescriptorSet::WORLD, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT); |
|
|
|
|
|
|
|
// texture
|
|
|
|
|
|
|
|
addBinding(DescriptorSet::WORLD, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT); |
|
|
|
|
|
|
|
|
|
|
|
// vertices
|
|
|
|
// vertices
|
|
|
|
addBinding(DescriptorSet::MESH, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT); |
|
|
|
addBinding(DescriptorSet::MESH, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT); |
|
|
@ -89,6 +93,24 @@ void DescriptorPool::bindBuffer(const Buffer& buffer, VkDescriptorType type, Des |
|
|
|
vkUpdateDescriptorSets(Instance::GetDevice(), 1, &descriptorWrite, 0, nullptr); |
|
|
|
vkUpdateDescriptorSets(Instance::GetDevice(), 1, &descriptorWrite, 0, nullptr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DescriptorPool::bindImage(const Image &image, VkDescriptorType type, DescriptorSet set, uint32_t binding) { |
|
|
|
|
|
|
|
VkDescriptorImageInfo imageInfo {}; |
|
|
|
|
|
|
|
imageInfo.imageView = image.view; |
|
|
|
|
|
|
|
imageInfo.sampler = image.sampler; |
|
|
|
|
|
|
|
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkWriteDescriptorSet descriptorWrite {}; |
|
|
|
|
|
|
|
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
|
|
|
|
|
|
|
descriptorWrite.dstSet = sets[set]; |
|
|
|
|
|
|
|
descriptorWrite.dstBinding = binding; |
|
|
|
|
|
|
|
descriptorWrite.dstArrayElement = 0; |
|
|
|
|
|
|
|
descriptorWrite.descriptorType = type; |
|
|
|
|
|
|
|
descriptorWrite.descriptorCount = 1; |
|
|
|
|
|
|
|
descriptorWrite.pImageInfo = &imageInfo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vkUpdateDescriptorSets(Instance::GetDevice(), 1, &descriptorWrite, 0, nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DescriptorPool::createLayout(DescriptorSet set, const std::vector<VkDescriptorSetLayoutBinding> &bindings) { |
|
|
|
void DescriptorPool::createLayout(DescriptorSet set, const std::vector<VkDescriptorSetLayoutBinding> &bindings) { |
|
|
|
VkDescriptorSetLayoutCreateInfo layoutCreateInfo {}; |
|
|
|
VkDescriptorSetLayoutCreateInfo layoutCreateInfo {}; |
|
|
|
layoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
|
|
|
layoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
|
|
|