Skip to content

Commit 3d38502

Browse files
committed
Initial mapping of vertex array to descriptors
1 parent 3b986a0 commit 3d38502

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

include/vsg/utils/GraphicsPipelineConfigurator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace vsg
132132
ref_ptr<ShaderCompileSettings> shaderHints;
133133
ref_ptr<DescriptorConfigurator> descriptorConfigurator;
134134
StateCommands inheritedState;
135+
std::map<uint32_t, VkVertexInputRate> vertexInputRates;
135136

136137
int compare(const Object& rhs) const override;
137138

src/vsg/utils/GraphicsPipelineConfigurator.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ void GraphicsPipelineConfigurator::reset()
427427
shaderHints->defines.clear();
428428
if (descriptorConfigurator) descriptorConfigurator->reset();
429429

430+
vertexInputRates.clear();
431+
432+
430433
_assignShaderSetSettings();
431434
}
432435

@@ -456,15 +459,21 @@ struct SetPipelineStates : public Visitor
456459

457460
bool GraphicsPipelineConfigurator::enableArray(const std::string& name, VkVertexInputRate vertexInputRate, uint32_t stride, VkFormat format)
458461
{
459-
auto& attributeBinding = shaderSet->getAttributeBinding(name);
460-
if (attributeBinding)
462+
if (auto& attributeBinding = shaderSet->getAttributeBinding(name))
461463
{
462464
if (!attributeBinding.define.empty()) shaderHints->defines.insert(attributeBinding.define);
463465

464466
SetPipelineStates setVertexAttributeState(baseAttributeBinding, attributeBinding, vertexInputRate, stride, format);
465467
accept(setVertexAttributeState);
466468
return true;
467469
}
470+
471+
if (const auto& descriptorBinding = shaderSet->getDescriptorBinding(name))
472+
{
473+
enableDescriptor(name);
474+
vertexInputRates[descriptorBinding.binding] = vertexInputRate;
475+
}
476+
468477
return false;
469478
}
470479

@@ -482,8 +491,7 @@ bool GraphicsPipelineConfigurator::enableDescriptor(const std::string& name)
482491

483492
bool GraphicsPipelineConfigurator::assignArray(DataList& arrays, const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr<Data> array)
484493
{
485-
const auto& attributeBinding = shaderSet->getAttributeBinding(name);
486-
if (attributeBinding)
494+
if (const auto& attributeBinding = shaderSet->getAttributeBinding(name))
487495
{
488496
if (!attributeBinding.define.empty()) shaderHints->defines.insert(attributeBinding.define);
489497

@@ -495,6 +503,14 @@ bool GraphicsPipelineConfigurator::assignArray(DataList& arrays, const std::stri
495503
arrays.push_back(array);
496504
return true;
497505
}
506+
507+
508+
if (const auto& descriptorBinding = shaderSet->getDescriptorBinding(name))
509+
{
510+
assignDescriptor(name, array, 0);
511+
vertexInputRates[descriptorBinding.binding] = vertexInputRate;
512+
}
513+
498514
return false;
499515
}
500516

@@ -740,6 +756,25 @@ void GraphicsPipelineConfigurator::_assignInheritedSets()
740756

741757
void GraphicsPipelineConfigurator::init()
742758
{
759+
if (!vertexInputRates.empty())
760+
{
761+
vsg::info("vertexInputRates max entry: ", vertexInputRates.rbegin()->first);
762+
for(auto [binding, rate] : vertexInputRates)
763+
{
764+
vsg::info(" { ", binding, ", ", rate, " }");
765+
}
766+
767+
if (const auto& descriptorBinding = shaderSet->getDescriptorBinding("vertexInputRates"))
768+
{
769+
vsg::info(" we have descriptor to assign vertexInputRates to { ", descriptorBinding.set, ", ", descriptorBinding.binding, " }");
770+
}
771+
else
772+
{
773+
vsg::warn("Missing DescriptorBinding for vertexInputRates.");
774+
775+
}
776+
}
777+
743778
_assignInheritedSets();
744779

745780
if (descriptorConfigurator)
@@ -749,6 +784,7 @@ void GraphicsPipelineConfigurator::init()
749784
shaderHints->defines.insert(descriptorConfigurator->defines.begin(), descriptorConfigurator->defines.end());
750785
}
751786

787+
752788
layout = shaderSet->createPipelineLayout(shaderHints->defines);
753789
graphicsPipeline = GraphicsPipeline::create(layout, shaderSet->getShaderStages(shaderHints), pipelineStates, subpass);
754790
bindGraphicsPipeline = vsg::BindGraphicsPipeline::create(graphicsPipeline);

0 commit comments

Comments
 (0)