Commit 3b7e205c by Jamie Madill

Fix matrix input attributes and formats.

We can't assume we have a simple mapping between input attribs and shader attribs. The app specifies matrix input attribs as several vector inputs, while the shader uses a single matrix type. BUG=angle:576 Change-Id: I4e3cdde4a14a5f06b86052dfe0325113cbe8e599 Reviewed-on: https://chromium-review.googlesource.com/189193Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 4d161bad
......@@ -287,68 +287,66 @@ std::string DynamicHLSL::generateVaryingHLSL(FragmentShader *fragmentShader, con
std::string DynamicHLSL::generateInputLayoutHLSL(const VertexFormat inputLayout[], const sh::Attribute shaderAttributes[]) const
{
std::string vertexHLSL;
vertexHLSL += "struct VS_INPUT\n"
"{\n";
std::string structHLSL, initHLSL;
int semanticIndex = 0;
unsigned int inputIndex = 0;
for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
{
const VertexFormat &vertexFormat = inputLayout[attributeIndex];
ASSERT(inputIndex < MAX_VERTEX_ATTRIBS);
const VertexFormat &vertexFormat = inputLayout[inputIndex];
const sh::Attribute &shaderAttribute = shaderAttributes[attributeIndex];
if (!shaderAttribute.name.empty())
{
// HLSL code for input structure
if (IsMatrixType(shaderAttribute.type))
{
// Matrix types are always transposed
vertexHLSL += " " + gl_d3d::HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type));
structHLSL += " " + gl_d3d::HLSLMatrixTypeString(TransposeMatrixType(shaderAttribute.type));
}
else
{
GLenum componentType = mRenderer->getVertexComponentType(vertexFormat);
vertexHLSL += " " + gl_d3d::HLSLComponentTypeString(componentType, UniformComponentCount(shaderAttribute.type));
structHLSL += " " + gl_d3d::HLSLComponentTypeString(componentType, UniformComponentCount(shaderAttribute.type));
}
vertexHLSL += " " + decorateAttribute(shaderAttribute.name) + " : TEXCOORD" + Str(semanticIndex) + ";\n";
structHLSL += " " + decorateAttribute(shaderAttribute.name) + " : TEXCOORD" + Str(semanticIndex) + ";\n";
semanticIndex += AttributeRegisterCount(shaderAttribute.type);
}
}
vertexHLSL += "};\n"
"\n"
"void initAttributes(VS_INPUT input)\n"
"{\n";
for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
{
const VertexFormat &vertexFormat = inputLayout[attributeIndex];
const sh::Attribute &shaderAttribute = shaderAttributes[attributeIndex];
if (!shaderAttribute.name.empty())
{
vertexHLSL += " " + decorateAttribute(shaderAttribute.name) + " = ";
// HLSL code for initialization
initHLSL += " " + decorateAttribute(shaderAttribute.name) + " = ";
// Mismatched vertex attribute to vertex input may result in an undefined
// data reinterpretation (eg for pure integer->float, float->pure integer)
// TODO: issue warning with gl debug info extension, when supported
if ((mRenderer->getVertexConversionType(vertexFormat) & rx::VERTEX_CONVERT_GPU) != 0)
if (IsMatrixType(shaderAttribute.type) ||
(mRenderer->getVertexConversionType(vertexFormat) & rx::VERTEX_CONVERT_GPU) != 0)
{
vertexHLSL += generateAttributeConversionHLSL(vertexFormat, shaderAttribute);
initHLSL += generateAttributeConversionHLSL(vertexFormat, shaderAttribute);
}
else
{
vertexHLSL += "input." + decorateAttribute(shaderAttribute.name);
initHLSL += "input." + decorateAttribute(shaderAttribute.name);
}
vertexHLSL += ";\n";
initHLSL += ";\n";
}
}
vertexHLSL += "}\n";
inputIndex += VariableRowCount(shaderAttribute.type);
}
return vertexHLSL;
return "struct VS_INPUT\n"
"{\n" +
structHLSL +
"};\n"
"\n"
"void initAttributes(VS_INPUT input)\n"
"{\n" +
initHLSL +
"}\n";
}
bool DynamicHLSL::generateShaderLinkHLSL(InfoLog &infoLog, int registers, const sh::ShaderVariable *packing[][4],
......
......@@ -52,17 +52,24 @@ unsigned int ParseAndStripArrayIndex(std::string* name)
void GetInputLayoutFromShader(const std::vector<sh::Attribute> &shaderAttributes, VertexFormat inputLayout[MAX_VERTEX_ATTRIBS])
{
size_t layoutIndex = 0;
for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); attributeIndex++)
{
ASSERT(layoutIndex < MAX_VERTEX_ATTRIBS);
const sh::Attribute &shaderAttr = shaderAttributes[attributeIndex];
VertexFormat *defaultFormat = &inputLayout[attributeIndex];
if (shaderAttr.type != GL_NONE)
{
defaultFormat->mType = UniformComponentType(shaderAttr.type);
defaultFormat->mNormalized = false;
defaultFormat->mPureInteger = (defaultFormat->mType != GL_FLOAT); // note: inputs can not be bool
defaultFormat->mComponents = UniformComponentCount(shaderAttr.type);
for (size_t rowIndex = 0; static_cast<int>(rowIndex) < VariableRowCount(shaderAttr.type); rowIndex++, layoutIndex++)
{
VertexFormat *defaultFormat = &inputLayout[layoutIndex];
defaultFormat->mType = UniformComponentType(shaderAttr.type);
defaultFormat->mNormalized = false;
defaultFormat->mPureInteger = (defaultFormat->mType != GL_FLOAT); // note: inputs can not be bool
defaultFormat->mComponents = VariableColumnCount(shaderAttr.type);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment