somewhat working material system

This commit is contained in:
2026-02-06 15:43:22 +02:00
parent 7ac98cf9ba
commit 898bf90504
9 changed files with 140 additions and 17 deletions

View File

@@ -61,17 +61,36 @@ void CVkShader::Build()
VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT,
};
VkPipelineLayoutCreateInfo stPipelineLayout = {};
stPipelineLayout.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
vkCreatePipelineLayout(m_hDevice, &stPipelineLayout, NULL, &m_hPipelineLayout);
CUtlVector<VkDescriptorSetLayoutBinding> bindings = {};
// TODO: Filter by vulkan shaders at some points
stages.Resize(m_shader.m_objects.GetSize());
modules.Resize(m_shader.m_objects.GetSize());
for ( int i = 0; i < m_shader.m_objects.GetSize(); i++ )
{
V_printf("a: %p\n", m_shader.m_lumps[i].m_pAddress);
VulkanInputMetaData_t *pMetaData = (VulkanInputMetaData_t*)m_shader.GetLumpPtr(m_shader.m_objects[i].m_nMetadataLump);
for ( int u = 0; u < pMetaData->nDescriptorsCount; u++ )
{
VulkanDescriptor_t *pDescriptor = (VulkanDescriptor_t*)m_shader.GetLumpPtr(pMetaData->pDescriptorSets);
V_printf("%s\n" ,pDescriptor->szName);
bool bFound = false;
for ( auto &b: bindings )
{
if (b.binding != pDescriptor->uBinding)
continue;
bFound = true;
break;
}
if (bFound)
break;
VkDescriptorSetLayoutBinding bind = {};
bind.binding = pDescriptor->uBinding;
bind.descriptorCount = 1;
bind.descriptorType = pDescriptor->eDescriptorType;
bind.stageFlags = VK_SHADER_STAGE_ALL;
bindings.AppendTail(bind);
m_bindings.AppendTail(*pDescriptor);
}
modules[i].sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
modules[i].pCode = (uint32_t*)m_shader.GetLumpPtr(m_shader.m_objects[i].m_nDataLump);
modules[i].codeSize = m_shader.GetLumpSize(m_shader.m_objects[i].m_nDataLump);
@@ -81,6 +100,22 @@ void CVkShader::Build()
stages[i].stage = VulkanGetShaderStage(m_shader.m_objects[i].m_eStage);
}
if ( bindings.GetSize() >= 0 )
{
m_setLayouts.Resize(1);
VkDescriptorSetLayoutCreateInfo stSetLayoutCreateInfo = {};
stSetLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
stSetLayoutCreateInfo.pBindings = bindings.GetData();
stSetLayoutCreateInfo.bindingCount = bindings.GetSize();
stSetLayoutCreateInfo.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT;
vkCreateDescriptorSetLayout(m_hDevice, &stSetLayoutCreateInfo, NULL, m_setLayouts.GetData());
stPipelineLayout.setLayoutCount = 1;
stPipelineLayout.pSetLayouts = m_setLayouts.GetData();
}
stPipelineLayout.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
vkCreatePipelineLayout(m_hDevice, &stPipelineLayout, NULL, &m_hPipelineLayout);
vertexInput.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInput.vertexBindingDescriptionCount = m_layouts.GetSize();
vertexInput.pVertexBindingDescriptions = m_layouts.GetData();