Pixel shaders support MRT output.

TRAC #22668 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@2023 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 245e4e09
...@@ -217,7 +217,18 @@ void OutputHLSL::header() ...@@ -217,7 +217,18 @@ void OutputHLSL::header()
out << "// Varyings\n"; out << "// Varyings\n";
out << varyings; out << varyings;
out << "\n" out << "\n"
"static float4 gl_Color[1] = {float4(0, 0, 0, 0)};\n"; "static float4 gl_Color[" << numColorValues << "] =\n"
"{\n";
for (unsigned int i = 0; i < numColorValues; i++)
{
out << " float4(0, 0, 0, 0)";
if (i + 1 != numColorValues)
{
out << ",";
}
out << "\n";
}
out << "};\n";
if (mUsesFragCoord) if (mUsesFragCoord)
{ {
......
...@@ -1162,6 +1162,15 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1162,6 +1162,15 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
return false; return false;
} }
bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
bool usesFragColor = fragmentShader->mUsesFragColor;
bool usesFragData = fragmentShader->mUsesFragData;
if (usesMRT && usesFragColor && usesFragData)
{
infoLog.append("Cannot use both gl_FragColor and gl_FragData in the same fragment shader.");
return false;
}
// Write the HLSL input/output declarations // Write the HLSL input/output declarations
const int shaderModel = mRenderer->getMajorShaderModel(); const int shaderModel = mRenderer->getMajorShaderModel();
const int maxVaryingVectors = mRenderer->getMaxVaryingVectors(); const int maxVaryingVectors = mRenderer->getMaxVaryingVectors();
...@@ -1213,6 +1222,8 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1213,6 +1222,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";
const unsigned int renderTargetCount = usesMRT ? mRenderer->getMaxRenderTargets() : 1;
// special varyings that use reserved registers // special varyings that use reserved registers
int reservedRegisterIndex = registers; int reservedRegisterIndex = registers;
std::string fragCoordSemantic; std::string fragCoordSemantic;
...@@ -1459,11 +1470,16 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1459,11 +1470,16 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
pixelHLSL += "};\n" pixelHLSL += "};\n"
"\n" "\n"
"struct PS_OUTPUT\n" "struct PS_OUTPUT\n"
"{\n" "{\n";
" float4 gl_Color[1] : " + targetSemantic + ";\n"
"};\n" for (unsigned int i = 0; i < renderTargetCount; i++)
{
pixelHLSL += " float4 gl_Color" + str(i) + " : " + targetSemantic + str(i) + ";\n";
}
pixelHLSL += "};\n"
"\n"; "\n";
if (fragmentShader->mUsesFrontFacing) if (fragmentShader->mUsesFrontFacing)
{ {
if (shaderModel >= 4) if (shaderModel >= 4)
...@@ -1565,9 +1581,16 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying ...@@ -1565,9 +1581,16 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
pixelHLSL += "\n" pixelHLSL += "\n"
" gl_main();\n" " gl_main();\n"
"\n" "\n"
" PS_OUTPUT output;\n" " PS_OUTPUT output;\n";
" output.gl_Color[0] = gl_Color[0];\n"
"\n" for (unsigned int i = 0; i < renderTargetCount; i++)
{
unsigned int sourceColor = fragmentShader->mUsesFragData ? i : 0;
pixelHLSL += " output.gl_Color" + str(i) + " = gl_Color[" + str(sourceColor) + "];\n";
}
pixelHLSL += "\n"
" return output;\n" " return output;\n"
"}\n"; "}\n";
......
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