rsx/d3d12/gl: Make output write backend dependent.

This commit is contained in:
Vincent Lejeune 2015-11-30 19:39:14 +01:00
parent 6fae5863cf
commit 929f518ef3
4 changed files with 37 additions and 22 deletions

View File

@ -319,11 +319,6 @@ std::string FragmentProgramDecompiler::BuildCode()
{ {
//main += fmt::format("\tgl_FragColor = %c0;\n", m_ctrl & 0x40 ? 'r' : 'h'); //main += fmt::format("\tgl_FragColor = %c0;\n", m_ctrl & 0x40 ? 'r' : 'h');
if (m_ctrl & 0xe)
{
main += m_ctrl & 0x40 ? "\tgl_FragDepth = r1.z;\n" : "\tgl_FragDepth = h0.z;\n";
}
std::stringstream OS; std::stringstream OS;
insertHeader(OS); insertHeader(OS);
OS << std::endl; OS << std::endl;

View File

@ -88,10 +88,10 @@ void D3D12FragmentDecompiler::insertOutputs(std::stringstream & OS)
OS << "{" << std::endl; OS << "{" << std::endl;
const std::pair<std::string, std::string> table[] = const std::pair<std::string, std::string> table[] =
{ {
{ "ocol0", m_ctrl & 0x40 ? "r0" : "h0" }, { "ocol0", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r0" : "h0" },
{ "ocol1", m_ctrl & 0x40 ? "r2" : "h4" }, { "ocol1", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r2" : "h4" },
{ "ocol2", m_ctrl & 0x40 ? "r3" : "h6" }, { "ocol2", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r3" : "h6" },
{ "ocol3", m_ctrl & 0x40 ? "r4" : "h8" }, { "ocol3", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r4" : "h8" },
}; };
for (int i = 0; i < sizeof(table) / sizeof(*table); ++i) for (int i = 0; i < sizeof(table) / sizeof(*table); ++i)
@ -99,6 +99,8 @@ void D3D12FragmentDecompiler::insertOutputs(std::stringstream & OS)
if (m_parr.HasParam(PF_PARAM_NONE, "float4", table[i].second)) if (m_parr.HasParam(PF_PARAM_NONE, "float4", table[i].second))
OS << " " << "float4" << " " << table[i].first << " : SV_TARGET" << i << ";" << std::endl; OS << " " << "float4" << " " << table[i].first << " : SV_TARGET" << i << ";" << std::endl;
} }
if (m_ctrl & CELL_GCM_SHADER_CONTROL_DEPTH_EXPORT)
OS << " float depth : SV_Depth;" << std::endl;
OS << "};" << std::endl; OS << "};" << std::endl;
} }
@ -166,19 +168,27 @@ void D3D12FragmentDecompiler::insertMainEnd(std::stringstream & OS)
{ {
const std::pair<std::string, std::string> table[] = const std::pair<std::string, std::string> table[] =
{ {
{ "ocol0", m_ctrl & 0x40 ? "r0" : "h0" }, { "ocol0", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r0" : "h0" },
{ "ocol1", m_ctrl & 0x40 ? "r2" : "h4" }, { "ocol1", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r2" : "h4" },
{ "ocol2", m_ctrl & 0x40 ? "r3" : "h6" }, { "ocol2", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r3" : "h6" },
{ "ocol3", m_ctrl & 0x40 ? "r4" : "h8" }, { "ocol3", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r4" : "h8" },
}; };
OS << " PixelOutput Out;" << std::endl; OS << " PixelOutput Out;" << std::endl;
size_t num_output = 0;
for (int i = 0; i < sizeof(table) / sizeof(*table); ++i) for (int i = 0; i < sizeof(table) / sizeof(*table); ++i)
{ {
if (m_parr.HasParam(PF_PARAM_NONE, "float4", table[i].second)) if (m_parr.HasParam(PF_PARAM_NONE, "float4", table[i].second))
{
OS << " Out." << table[i].first << " = " << table[i].second << ";" << std::endl; OS << " Out." << table[i].first << " = " << table[i].second << ";" << std::endl;
num_output++;
}
} }
OS << " if (isAlphaTested && Out.ocol0.a <= alphaRef) discard;" << std::endl; if (m_ctrl & CELL_GCM_SHADER_CONTROL_DEPTH_EXPORT)
OS << " Out.depth = " << ((m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS) ? "r1.z;" : "h0.z;") << std::endl;
// Shaders don't always output colors (for instance if they write to depth only)
if (num_output > 0)
OS << " if (isAlphaTested && Out.ocol0.a <= alphaRef) discard;" << std::endl;
OS << " return Out;" << std::endl; OS << " return Out;" << std::endl;
OS << "}" << std::endl; OS << "}" << std::endl;
} }

View File

@ -454,6 +454,12 @@ enum
CELL_GCM_FALSE = 0 CELL_GCM_FALSE = 0
}; };
enum
{
CELL_GCM_SHADER_CONTROL_DEPTH_EXPORT = 0xe, ///< shader program exports the depth of the shaded fragment
CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS = 0x40 ///< shader program exports 32 bits registers values (instead of 16 bits ones)
};
// GCM Reports // GCM Reports
enum enum
{ {

View File

@ -5,6 +5,7 @@
#include "GLFragmentProgram.h" #include "GLFragmentProgram.h"
#include "GLCommonDecompiler.h" #include "GLCommonDecompiler.h"
#include "../GCM.h"
std::string GLFragmentDecompilerThread::getFloatTypeName(size_t elementCount) std::string GLFragmentDecompilerThread::getFloatTypeName(size_t elementCount)
{ {
@ -44,10 +45,10 @@ void GLFragmentDecompilerThread::insertOutputs(std::stringstream & OS)
{ {
const std::pair<std::string, std::string> table[] = const std::pair<std::string, std::string> table[] =
{ {
{ "ocol0", m_ctrl & 0x40 ? "r0" : "h0" }, { "ocol0", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r0" : "h0" },
{ "ocol1", m_ctrl & 0x40 ? "r2" : "h4" }, { "ocol1", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r2" : "h4" },
{ "ocol2", m_ctrl & 0x40 ? "r3" : "h6" }, { "ocol2", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r3" : "h6" },
{ "ocol3", m_ctrl & 0x40 ? "r4" : "h8" }, { "ocol3", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r4" : "h8" },
}; };
for (int i = 0; i < sizeof(table) / sizeof(*table); ++i) for (int i = 0; i < sizeof(table) / sizeof(*table); ++i)
@ -103,10 +104,10 @@ void GLFragmentDecompilerThread::insertMainEnd(std::stringstream & OS)
{ {
const std::pair<std::string, std::string> table[] = const std::pair<std::string, std::string> table[] =
{ {
{ "ocol0", m_ctrl & 0x40 ? "r0" : "h0" }, { "ocol0", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r0" : "h0" },
{ "ocol1", m_ctrl & 0x40 ? "r2" : "h4" }, { "ocol1", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r2" : "h4" },
{ "ocol2", m_ctrl & 0x40 ? "r3" : "h6" }, { "ocol2", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r3" : "h6" },
{ "ocol3", m_ctrl & 0x40 ? "r4" : "h8" }, { "ocol3", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r4" : "h8" },
}; };
for (int i = 0; i < sizeof(table) / sizeof(*table); ++i) for (int i = 0; i < sizeof(table) / sizeof(*table); ++i)
@ -115,6 +116,9 @@ void GLFragmentDecompilerThread::insertMainEnd(std::stringstream & OS)
OS << " " << table[i].first << " = " << table[i].second << ";" << std::endl; OS << " " << table[i].first << " = " << table[i].second << ";" << std::endl;
} }
if (m_ctrl & CELL_GCM_SHADER_CONTROL_DEPTH_EXPORT)
OS << ((m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS) ? "\tgl_FragDepth = r1.z;\n" : "\tgl_FragDepth = h0.z;\n") << std::endl;
OS << "}" << std::endl; OS << "}" << std::endl;
} }