descriptor update
This commit is contained in:
parent
073205376f
commit
abc1d7da9f
8 changed files with 254 additions and 127 deletions
|
|
@ -33,105 +33,9 @@ import :VulkanShader;
|
|||
import :WindowWaylandVulkan;
|
||||
|
||||
namespace Crafter {
|
||||
struct DescriptorEntry {
|
||||
VkDescriptorType type;
|
||||
bool occured = true;
|
||||
};
|
||||
|
||||
export struct DescriptorSet {
|
||||
VkDescriptorSet set[2];
|
||||
void Write(VkWriteDescriptorSet* descriptors, std::uint32_t count) {
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, count, descriptors, 0, nullptr);
|
||||
}
|
||||
void Write(std::uint32_t stage, VkDescriptorType type, std::uint32_t binding, VkDescriptorBufferInfo* buffer) {
|
||||
VkWriteDescriptorSet write = vks::initializers::writeDescriptorSet(set[stage], type, binding, buffer);
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 1, &write, 0, nullptr);
|
||||
}
|
||||
void Write(std::uint32_t stage, VkDescriptorType type, std::uint32_t binding, VkDescriptorImageInfo* buffer) {
|
||||
VkWriteDescriptorSet write = vks::initializers::writeDescriptorSet(set[stage], type, binding, buffer);
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 1, &write, 0, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
export template <typename MeshShader, typename FragmentShader>
|
||||
class VulkanPipeline {
|
||||
private:
|
||||
consteval static std::uint32_t GetUniqueDiscriptorCount() {
|
||||
DescriptorEntry types[] = {{VK_DESCRIPTOR_TYPE_SAMPLER, 0},{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0},{VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 0},{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 0},{VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 0},{VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 0},{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0},{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0},{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 0},{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 0},{VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 0},{VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK, 0},{VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 0},{VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV, 0},{VK_DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM, 0},{VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM, 0},{VK_DESCRIPTOR_TYPE_MUTABLE_EXT, 0},{VK_DESCRIPTOR_TYPE_PARTITIONED_ACCELERATION_STRUCTURE_NV, 0},{VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT, 0},{VK_DESCRIPTOR_TYPE_MUTABLE_VALVE, 0}};
|
||||
|
||||
for(const DescriptorBinding& binding : MeshShader::descriptors) {
|
||||
for(DescriptorEntry& type : types) {
|
||||
if(type.type == binding.type) {
|
||||
type.occured = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(const DescriptorBinding& binding : FragmentShader::descriptors) {
|
||||
for(DescriptorEntry& type : types) {
|
||||
if(type.type == binding.type) {
|
||||
type.occured = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t size = 0;
|
||||
for(DescriptorEntry& type : types) {
|
||||
if(type.occured) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
constexpr static std::uint32_t uniqueDescriptorCount = GetUniqueDiscriptorCount();
|
||||
consteval static std::array<VkDescriptorPoolSize, uniqueDescriptorCount> GetPoolSizes() {
|
||||
std::array<VkDescriptorPoolSize, uniqueDescriptorCount> types = {};
|
||||
for(std::uint32_t i = 0; i < uniqueDescriptorCount; i++){
|
||||
types[i].descriptorCount = 12345;
|
||||
}
|
||||
|
||||
for(const DescriptorBinding& binding : MeshShader::descriptors) {
|
||||
bool found = false;
|
||||
for(VkDescriptorPoolSize& type : types) {
|
||||
if(type.type == binding.type && type.descriptorCount != 12345) {
|
||||
type.descriptorCount++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
for(std::uint32_t i = 0; i < uniqueDescriptorCount; i++){
|
||||
if(types[i].descriptorCount == 12345) {
|
||||
types[i].type = binding.type;
|
||||
types[i].descriptorCount = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(const DescriptorBinding& binding : FragmentShader::descriptors) {
|
||||
bool found = false;
|
||||
for(VkDescriptorPoolSize& type : types) {
|
||||
if(type.type == binding.type) {
|
||||
type.descriptorCount++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
for(std::uint32_t i = 0; i < uniqueDescriptorCount; i++){
|
||||
if(types[i].descriptorCount == 12345) {
|
||||
types[i].type = binding.type;
|
||||
types[i].descriptorCount = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
template <typename Shader, VkShaderStageFlagBits Flag>
|
||||
consteval static std::array<VkDescriptorSetLayoutBinding, Shader::descriptorCount> GetDescriptorSet() {
|
||||
std::array<VkDescriptorSetLayoutBinding, Shader::descriptorCount> set;
|
||||
|
|
@ -145,15 +49,9 @@ namespace Crafter {
|
|||
public:
|
||||
inline static VkPipeline pipeline;
|
||||
inline static VkPipelineLayout pipelineLayout;
|
||||
inline static VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
|
||||
inline static VkDescriptorSetLayout descriptorSetLayout[2];
|
||||
|
||||
static void CreatePipeline() {
|
||||
// Pool
|
||||
std::array<VkDescriptorPoolSize, uniqueDescriptorCount> poolSizes = GetPoolSizes();
|
||||
VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(uniqueDescriptorCount, poolSizes.data(), 2);
|
||||
VulkanDevice::CHECK_VK_RESULT(vkCreateDescriptorPool(VulkanDevice::device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
||||
|
||||
// Layout
|
||||
constexpr std::array<VkDescriptorSetLayoutBinding, MeshShader::descriptorCount> setLayoutBindingsMesh = GetDescriptorSet<MeshShader, VK_SHADER_STAGE_MESH_BIT_EXT>();
|
||||
VkDescriptorSetLayoutCreateInfo descriptorLayoutInfoMesh = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindingsMesh.data(), MeshShader::descriptorCount);
|
||||
|
|
@ -223,10 +121,5 @@ namespace Crafter {
|
|||
|
||||
VulkanDevice::CHECK_VK_RESULT(vkCreateGraphicsPipelines(VulkanDevice::device, VK_NULL_HANDLE, 1, &pipelineCI, nullptr, &pipeline));
|
||||
}
|
||||
|
||||
static void GetDescriptorSet(DescriptorSet& set) {
|
||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout[0], 2);
|
||||
VulkanDevice::CHECK_VK_RESULT(vkAllocateDescriptorSets(VulkanDevice::device, &allocInfo, set.set));
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue