Commit 5a812555 authored by Simeon Hermann's avatar Simeon Hermann
Browse files

[#36] add reflection of descriptor sets, not working yet

parent 996a1ffb
Pipeline #25532 failed with stages
in 1 minute and 38 seconds
......@@ -69,8 +69,6 @@ set(vkcv_sources
${vkcv_source}/vkcv/SamplerManager.cpp
${vkcv_include}/vkcv/DescriptorWrites.hpp
${vkcv_include}/vkcv/DescriptorSetLayout.hpp
${vkcv_include}/vkcv/DrawcallRecording.hpp
${vkcv_source}/vkcv/DrawcallRecording.cpp
......
......@@ -33,11 +33,13 @@ namespace vkcv
struct DescriptorBinding
{
DescriptorBinding(
uint32_t bindingID,
DescriptorType descriptorType,
uint32_t descriptorCount,
ShaderStage shaderStage
) noexcept;
uint32_t bindingID;
DescriptorType descriptorType;
uint32_t descriptorCount;
ShaderStage shaderStage;
......
#pragma once
#include <unordered_map>
#include <vector>
#include <iostream>
namespace vkcv{
struct DescriptorSetLayout{
inline DescriptorSetLayout() noexcept: sampledImages(),
storageImages(),
uniformBuffers(),
storageBuffers(),
samplers() {};
inline DescriptorSetLayout(std::vector<uint32_t> sampledImageVec,
std::vector<uint32_t> storageImageVec,
std::vector<uint32_t> uniformBufferVec,
std::vector<uint32_t> storageBufferVec,
std::vector<uint32_t> samplerVec) noexcept:
sampledImages(sampledImageVec),
storageImages(storageImageVec),
uniformBuffers(uniformBufferVec),
storageBuffers(storageBufferVec),
samplers(samplerVec) {};
std::vector<uint32_t> sampledImages;
std::vector<uint32_t> storageImages;
std::vector<uint32_t> uniformBuffers;
std::vector<uint32_t> storageBuffers;
std::vector<uint32_t> samplers;
};
}
......@@ -8,11 +8,12 @@
#include <unordered_map>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <filesystem>
#include <vulkan/vulkan.hpp>
#include <spirv_cross.hpp>
#include "vkcv/VertexLayout.hpp"
#include "vkcv/DescriptorSetLayout.hpp"
#include "vkcv/DescriptorConfig.hpp"
namespace vkcv {
......@@ -61,13 +62,13 @@ namespace vkcv {
const VertexLayout &getVertexLayout() const;
size_t getPushConstantSize() const;
const DescriptorSetLayout &getDescriptorSetLayout() const;
const std::vector<std::vector<DescriptorBinding>> getReflectedDescriptors() const;
private:
std::unordered_map<ShaderStage, Shader> m_Shaders;
VertexLayout m_VertexLayout;
DescriptorSetLayout m_DescriptorSetLayout;
std::vector<std::vector<DescriptorBinding>> m_DescriptorSets;
size_t m_pushConstantSize = 0;
};
}
......@@ -94,9 +94,9 @@ int main(int argc, const char** argv) {
return static_cast<uint32_t>(x.type) < static_cast<uint32_t>(y.type);
});
uint32_t setID = 0;
std::vector<vkcv::DescriptorBinding> descriptorBindings = {
vkcv::DescriptorBinding(vkcv::DescriptorType::IMAGE_SAMPLED, 1, vkcv::ShaderStage::FRAGMENT),
vkcv::DescriptorBinding(vkcv::DescriptorType::SAMPLER, 1, vkcv::ShaderStage::FRAGMENT) };
triangleShaderProgram.getReflectedDescriptors()[setID] };
vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorBindings);
const vkcv::PipelineConfig trianglePipelineDefinition(
......
......@@ -2,10 +2,12 @@
namespace vkcv {
DescriptorBinding::DescriptorBinding(
uint32_t bindingID,
DescriptorType descriptorType,
uint32_t descriptorCount,
ShaderStage shaderStage) noexcept
:
bindingID(bindingID),
descriptorType(descriptorType),
descriptorCount(descriptorCount),
shaderStage(shaderStage) {}
......
......@@ -40,7 +40,7 @@ namespace vkcv
//create each set's binding
for (uint32_t i = 0; i < bindings.size(); i++) {
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding(
i,
bindings[i].bindingID,
convertDescriptorTypeFlag(bindings[i].descriptorType),
bindings[i].descriptorCount,
convertShaderStageFlag(bindings[i].shaderStage));
......
......@@ -5,7 +5,6 @@
*/
#include "vkcv/ShaderProgram.hpp"
#include <algorithm>
namespace vkcv {
/**
......@@ -68,7 +67,7 @@ namespace vkcv {
ShaderProgram::ShaderProgram() noexcept :
m_Shaders{},
m_VertexLayout{},
m_DescriptorSetLayout{}
m_DescriptorSets{}
{}
bool ShaderProgram::addShader(ShaderStage shaderStage, const std::filesystem::path &shaderPath)
......@@ -131,40 +130,63 @@ namespace vkcv {
}
//Descriptor Sets
//Storage buffer, uniform Buffer, storage image, sampled image, sampler (?)
//Uniform buffer, storage buffer, sampler, sampled image, storage image
std::vector<uint32_t> separateImageVec;
for (uint32_t i = 0; i < resources.separate_images.size(); i++) {
auto &u = resources.separate_images[i];
separateImageVec.push_back(comp.get_decoration(u.id, spv::DecorationDescriptorSet));
std::vector<std::pair<uint32_t, DescriptorBinding>> bindings;
int32_t maxSetID = -1;
for (uint32_t i = 0; i < resources.uniform_buffers.size(); i++) {
auto& u = resources.uniform_buffers[i];
const spirv_cross::SPIRType& base_type = comp.get_type(u.base_type_id);
std::pair descriptor(comp.get_decoration(u.id, spv::DecorationDescriptorSet),
DescriptorBinding(comp.get_decoration(u.id, spv::DecorationBinding), DescriptorType::UNIFORM_BUFFER, base_type.vecsize, shaderStage));
bindings.push_back(descriptor);
if (comp.get_decoration(u.id, spv::DecorationDescriptorSet) > maxSetID) maxSetID = comp.get_decoration(u.id, spv::DecorationDescriptorSet);
}
std::vector<uint32_t> storageImageVec;
for (uint32_t i = 0; i < resources.storage_images.size(); i++) {
auto &u = resources.storage_images[i];
storageImageVec.push_back(comp.get_decoration(u.id, spv::DecorationDescriptorSet));
for (uint32_t i = 0; i < resources.storage_buffers.size(); i++) {
auto& u = resources.storage_buffers[i];
const spirv_cross::SPIRType& base_type = comp.get_type(u.base_type_id);
std::pair descriptor(comp.get_decoration(u.id, spv::DecorationDescriptorSet),
DescriptorBinding(comp.get_decoration(u.id, spv::DecorationBinding), DescriptorType::STORAGE_BUFFER, base_type.vecsize, shaderStage));
bindings.push_back(descriptor);
if (comp.get_decoration(u.id, spv::DecorationDescriptorSet) > maxSetID) maxSetID = comp.get_decoration(u.id, spv::DecorationDescriptorSet);
}
std::vector<uint32_t> uniformBufferVec;
for (uint32_t i = 0; i < resources.uniform_buffers.size(); i++) {
auto &u = resources.uniform_buffers[i];
uniformBufferVec.push_back(comp.get_decoration(u.id, spv::DecorationDescriptorSet));
for (uint32_t i = 0; i < resources.separate_samplers.size(); i++) {
auto& u = resources.separate_samplers[i];
const spirv_cross::SPIRType& base_type = comp.get_type(u.base_type_id);
std::pair descriptor(comp.get_decoration(u.id, spv::DecorationDescriptorSet),
DescriptorBinding(comp.get_decoration(u.id, spv::DecorationBinding), DescriptorType::SAMPLER, base_type.vecsize, shaderStage));
bindings.push_back(descriptor);
if (comp.get_decoration(u.id, spv::DecorationDescriptorSet) > maxSetID) maxSetID = comp.get_decoration(u.id, spv::DecorationDescriptorSet);
}
std::vector<uint32_t> storageBufferVec;
for (uint32_t i = 0; i < resources.storage_buffers.size(); i++) {
auto &u = resources.storage_buffers[i];
storageBufferVec.push_back(comp.get_decoration(u.id, spv::DecorationDescriptorSet));
for (uint32_t i = 0; i < resources.separate_images.size(); i++) {
auto& u = resources.separate_images[i];
const spirv_cross::SPIRType& base_type = comp.get_type(u.base_type_id);
std::pair descriptor(comp.get_decoration(u.id, spv::DecorationDescriptorSet),
DescriptorBinding(comp.get_decoration(u.id, spv::DecorationBinding), DescriptorType::IMAGE_SAMPLED, base_type.vecsize, shaderStage));
bindings.push_back(descriptor);
if (comp.get_decoration(u.id, spv::DecorationDescriptorSet) > maxSetID) maxSetID = comp.get_decoration(u.id, spv::DecorationDescriptorSet);
}
std::vector<uint32_t> samplerVec;
for (uint32_t i = 0; i < resources.separate_samplers.size(); i++) {
auto &u = resources.separate_samplers[i];
samplerVec.push_back(comp.get_decoration(u.id, spv::DecorationDescriptorSet));
for (uint32_t i = 0; i < resources.storage_images.size(); i++) {
auto& u = resources.storage_images[i];
const spirv_cross::SPIRType& base_type = comp.get_type(u.base_type_id);
std::pair descriptor(comp.get_decoration(u.id, spv::DecorationDescriptorSet),
DescriptorBinding(comp.get_decoration(u.id, spv::DecorationBinding), DescriptorType::IMAGE_STORAGE, base_type.vecsize, shaderStage));
bindings.push_back(descriptor);
if (comp.get_decoration(u.id, spv::DecorationDescriptorSet) > maxSetID) maxSetID = comp.get_decoration(u.id, spv::DecorationDescriptorSet);
}
m_DescriptorSets.resize(maxSetID);
for (auto binding : bindings) {
m_DescriptorSets[binding.first].push_back(binding.second);
}
m_DescriptorSetLayout = DescriptorSetLayout(separateImageVec, storageImageVec, uniformBufferVec, storageBufferVec, samplerVec);
//reflect push constants
for (const auto &pushConstantBuffer : resources.push_constant_buffers) {
for (const auto &range : comp.get_active_buffer_ranges(pushConstantBuffer.id)) {
const size_t size = range.range + range.offset;
......@@ -177,8 +199,8 @@ namespace vkcv {
return m_VertexLayout;
}
const DescriptorSetLayout& ShaderProgram::getDescriptorSetLayout() const {
return m_DescriptorSetLayout;
const std::vector<std::vector<DescriptorBinding>> ShaderProgram::getReflectedDescriptors() const {
return m_DescriptorSets;
}
size_t ShaderProgram::getPushConstantSize() const {
return m_pushConstantSize;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment