MESH BUFFER

This commit is contained in:
Jorijn van der Graaf 2025-04-27 01:57:25 +02:00
commit 523852da08
11 changed files with 93 additions and 51 deletions

View file

@ -23,7 +23,7 @@ import :WindowWaylandVulkan;
namespace Crafter {
struct DescriptorEntry {
VkDescriptorType type;
std::uint32_t occurrences = 0;
bool occured = true;
};
export template <typename MeshShader, typename FragmentShader>
@ -35,7 +35,7 @@ namespace Crafter {
for(const DescriptorBinding& binding : MeshShader::descriptors) {
for(DescriptorEntry& type : types) {
if(type.type == binding.type) {
type.occurrences++;
type.occured = true;
}
}
}
@ -43,14 +43,16 @@ namespace Crafter {
for(const DescriptorBinding& binding : FragmentShader::descriptors) {
for(DescriptorEntry& type : types) {
if(type.type == binding.type) {
type.occurrences++;
type.occured = true;
}
}
}
std::uint32_t size = 0;
for(DescriptorEntry& type : types) {
size+=type.occurrences;
if(type.occured) {
size++;
}
}
return size;
@ -58,30 +60,46 @@ namespace Crafter {
constexpr static std::uint32_t uniqueDescriptorCount = GetUniqueDiscriptorCount();
consteval static std::array<VkDescriptorPoolSize, uniqueDescriptorCount> GetPoolSizes() {
std::array<VkDescriptorPoolSize, uniqueDescriptorCount> types = {};
std::uint32_t i = 0;
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) {
if(type.type == binding.type && type.descriptorCount != 12345) {
type.descriptorCount++;
goto next;
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;
}
}
}
types[i].type = binding.type;
types[i].descriptorCount = 1;
next:;
}
for(const DescriptorBinding& binding : FragmentShader::descriptors) {
bool found = false;
for(VkDescriptorPoolSize& type : types) {
if(type.type == binding.type) {
type.descriptorCount++;
goto next2;
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;
}
}
}
types[i].type = binding.type;
types[i].descriptorCount = 1;
next2:;
}
return types;
@ -165,6 +183,7 @@ namespace Crafter {
shaderStages[0].pName = MeshShader::_entrypoint.value;
shaderStages[0].flags = 0;
shaderStages[0].pSpecializationInfo = nullptr;
shaderStages[0].pNext = nullptr;
// Fragment stage of the pipeline
shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
@ -173,6 +192,7 @@ namespace Crafter {
shaderStages[1].pName = FragmentShader::_entrypoint.value;
shaderStages[1].flags = 0;
shaderStages[1].pSpecializationInfo = nullptr;
shaderStages[1].pNext = nullptr;
VulkanDevice::CHECK_VK_RESULT(vkCreateGraphicsPipelines(VulkanDevice::device, VK_NULL_HANDLE, 1, &pipelineCI, nullptr, &pipeline));
}