Generate the same code once for fragment and vertex varyings.

TRAC #22857 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2153 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 7b2e6758
...@@ -957,6 +957,8 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -957,6 +957,8 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
std::string targetSemantic = (shaderModel >= 4) ? "SV_Target" : "COLOR"; std::string targetSemantic = (shaderModel >= 4) ? "SV_Target" : "COLOR";
std::string positionSemantic = (shaderModel >= 4) ? "SV_Position" : "POSITION"; std::string positionSemantic = (shaderModel >= 4) ? "SV_Position" : "POSITION";
std::string varyingHLSL = generateVaryingHLSL(fragmentShader, varyingSemantic);
const unsigned int renderTargetCount = usesMRT ? mRenderer->getMaxRenderTargets() : 1; const unsigned int renderTargetCount = usesMRT ? mRenderer->getMaxRenderTargets() : 1;
// special varyings that use reserved registers // special varyings that use reserved registers
...@@ -1016,12 +1018,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1016,12 +1018,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
vertexHLSL += " float4 gl_Position : " + positionSemantic + ";\n"; vertexHLSL += " float4 gl_Position : " + positionSemantic + ";\n";
} }
for (int r = 0; r < registers; r++) vertexHLSL += varyingHLSL;
{
int registerSize = packing[r][3] ? 4 : (packing[r][2] ? 3 : (packing[r][1] ? 2 : 1));
vertexHLSL += " float" + str(registerSize) + " v" + str(r) + " : " + varyingSemantic + str(r) + ";\n";
}
if (fragmentShader->mUsesFragCoord) if (fragmentShader->mUsesFragCoord)
{ {
...@@ -1156,22 +1153,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1156,22 +1153,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
pixelHLSL += "struct PS_INPUT\n" pixelHLSL += "struct PS_INPUT\n"
"{\n"; "{\n";
for (VaryingList::iterator varying = fragmentShader->mVaryings.begin(); varying != fragmentShader->mVaryings.end(); varying++) pixelHLSL += varyingHLSL;
{
if (varying->reg >= 0)
{
for (int i = 0; i < varying->size; i++)
{
int rows = VariableRowCount(varying->type);
for (int j = 0; j < rows; j++)
{
std::string n = str(varying->reg + i * rows + j);
pixelHLSL += " float" + str(VariableColumnCount(varying->type)) + " v" + n + " : " + varyingSemantic + n + ";\n";
}
}
}
else UNREACHABLE();
}
if (fragmentShader->mUsesFragCoord) if (fragmentShader->mUsesFragCoord)
{ {
...@@ -1337,6 +1319,38 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1337,6 +1319,38 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
return true; return true;
} }
std::string ProgramBinary::generateVaryingHLSL(FragmentShader *fragmentShader, const std::string &varyingSemantic) const
{
std::string varyingHLSL;
for (VaryingList::iterator varying = fragmentShader->mVaryings.begin(); varying != fragmentShader->mVaryings.end(); varying++)
{
if (varying->reg >= 0)
{
for (int i = 0; i < varying->size; i++)
{
int rows = VariableRowCount(varying->type);
for (int j = 0; j < rows; j++)
{
switch (varying->interpolation)
{
case Smooth: varyingHLSL += " "; break;
case Flat: varyingHLSL += " nointerpolation "; break;
case Centroid: varyingHLSL += " centroid "; break;
default: UNREACHABLE();
}
std::string n = str(varying->reg + i * rows + j);
varyingHLSL += "float" + str(VariableColumnCount(varying->type)) + " v" + n + " : " + varyingSemantic + n + ";\n";
}
}
}
else UNREACHABLE();
}
return varyingHLSL;
}
bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length) bool ProgramBinary::load(InfoLog &infoLog, const void *binary, GLsizei length)
{ {
BinaryInputStream stream(binary, length); BinaryInputStream stream(binary, length);
...@@ -1939,12 +1953,9 @@ std::string ProgramBinary::generatePointSpriteHLSL(int registers, const Varying ...@@ -1939,12 +1953,9 @@ std::string ProgramBinary::generatePointSpriteHLSL(int registers, const Varying
"struct GS_INPUT\n" "struct GS_INPUT\n"
"{\n"; "{\n";
for (int r = 0; r < registers; r++) std::string varyingHLSL = generateVaryingHLSL(fragmentShader, varyingSemantic);
{
int registerSize = packing[r][3] ? 4 : (packing[r][2] ? 3 : (packing[r][1] ? 2 : 1));
geomHLSL += " float" + str(registerSize) + " v" + str(r) + " : " + varyingSemantic + str(r) + ";\n"; geomHLSL += varyingHLSL;
}
if (fragmentShader->mUsesFragCoord) if (fragmentShader->mUsesFragCoord)
{ {
...@@ -1958,12 +1969,7 @@ std::string ProgramBinary::generatePointSpriteHLSL(int registers, const Varying ...@@ -1958,12 +1969,7 @@ std::string ProgramBinary::generatePointSpriteHLSL(int registers, const Varying
"struct GS_OUTPUT\n" "struct GS_OUTPUT\n"
"{\n"; "{\n";
for (int r = 0; r < registers; r++) geomHLSL += varyingHLSL;
{
int registerSize = packing[r][3] ? 4 : (packing[r][2] ? 3 : (packing[r][1] ? 2 : 1));
geomHLSL += " float" + str(registerSize) + " v" + str(r) + " : " + varyingSemantic + str(r) + ";\n";
}
if (fragmentShader->mUsesFragCoord) if (fragmentShader->mUsesFragCoord)
{ {
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -138,6 +138,7 @@ class ProgramBinary : public RefCountObject ...@@ -138,6 +138,7 @@ class ProgramBinary : public RefCountObject
bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4], bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4],
std::string& pixelHLSL, std::string& vertexHLSL, std::string& pixelHLSL, std::string& vertexHLSL,
FragmentShader *fragmentShader, VertexShader *vertexShader); FragmentShader *fragmentShader, VertexShader *vertexShader);
std::string generateVaryingHLSL(FragmentShader *fragmentShader, const std::string &varyingSemantic) const;
bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
......
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