Skip to content

Commit 98825ca

Browse files
author
Ashwin Bhat
committed
[VkShaderGen] Emit layout blocks for stage in/out
layout (location = 0) out VertexData { vec3 normalWorld; vec3 tangentWorld; vec3 positionWorld; } vd;
1 parent dcd0285 commit 98825ca

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

source/MaterialXGenGlsl/VkShaderGenerator.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,14 @@ void VkShaderGenerator::emitInputs(GenContext& context, ShaderStage& stage) cons
5454
const VariableBlock& vertexData = stage.getInputBlock(HW::VERTEX_DATA);
5555
if (!vertexData.empty())
5656
{
57-
emitComment("Inputs: " + vertexData.getName(), stage);
58-
for (size_t i = 0; i < vertexData.size(); ++i)
59-
{
60-
61-
emitLineBegin(stage);
62-
emitString("layout (location = " + std::to_string(i) + ") ", stage);
63-
emitVariableDeclaration(vertexData[i], _syntax->getInputQualifier(), context, stage, false);
64-
emitString(Syntax::SEMICOLON, stage);
65-
emitLineEnd(stage, false);
66-
}
57+
emitString("layout (location = " + std::to_string(vertexDataLocation) + ") " +
58+
_syntax->getInputQualifier() + " " + vertexData.getName(), stage);
59+
emitLineBreak(stage);
60+
emitScopeBegin(stage);
61+
emitVariableDeclarations(vertexData, EMPTY_STRING, Syntax::SEMICOLON, context, stage, false);
62+
emitScopeEnd(stage, false, false);
63+
emitString(" " + vertexData.getInstance() + Syntax::SEMICOLON, stage);
64+
emitLineBreak(stage);
6765
emitLineBreak(stage);
6866
}
6967
}
@@ -81,14 +79,14 @@ void VkShaderGenerator::emitOutputs(GenContext& context, ShaderStage& stage) con
8179
const VariableBlock& vertexData = stage.getOutputBlock(HW::VERTEX_DATA);
8280
if (!vertexData.empty())
8381
{
84-
for (size_t i = 0; i < vertexData.size(); ++i)
85-
{
86-
emitLineBegin(stage);
87-
emitString("layout (location = " + std::to_string(i) + ") ", stage);
88-
emitVariableDeclaration(vertexData[i], _syntax->getOutputQualifier(), context, stage, false);
89-
emitString(Syntax::SEMICOLON, stage);
90-
emitLineEnd(stage, false);
91-
}
82+
emitString("layout (location = " + std::to_string(vertexDataLocation) + ") " +
83+
_syntax->getOutputQualifier() + " " + vertexData.getName(), stage);
84+
emitLineBreak(stage);
85+
emitScopeBegin(stage);
86+
emitVariableDeclarations(vertexData, EMPTY_STRING, Syntax::SEMICOLON, context, stage, false);
87+
emitScopeEnd(stage, false, false);
88+
emitString(" " + vertexData.getInstance() + Syntax::SEMICOLON, stage);
89+
emitLineBreak(stage);
9290
emitLineBreak(stage);
9391
}
9492
}

source/MaterialXGenGlsl/VkShaderGenerator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class MX_GENGLSL_API VkShaderGenerator : public GlslShaderGenerator
5757
HwResourceBindingContextPtr getResourceBindingContext(GenContext&) const override;
5858

5959
VkResourceBindingContextPtr _resourceBindingCtx = nullptr;
60+
61+
// vertex data interface location to bind between stages
62+
int vertexDataLocation = 0;
6063
};
6164

6265
MATERIALX_NAMESPACE_END

0 commit comments

Comments
 (0)