gl/vk: Bug fixes and improvements (#2155)

* gl: Fix broken buffer reserve computation

* gl: Texture format fixes

* gl: Two sided lighting

* gl: Always update glsl output registers

* gl: Simplify vertex input declaration

* vk: Always write output registers

* vk/gl: swizzle component read on depth textures

* gl/vk: Use proper MVP matrix

gl: fix broken mvp when window_origin=top

* vk/gl: Move fragment operations block into the proxy function
This commit is contained in:
kd-11 2016-09-26 15:21:17 +03:00 committed by raven02
parent 38f35df7b6
commit 7884356e90
11 changed files with 420 additions and 110 deletions

View file

@ -198,13 +198,42 @@ static const reg_info reg_table[] =
void GLVertexDecompilerThread::insertOutputs(std::stringstream & OS, const std::vector<ParamType> & outputs)
{
for (const auto &i : reg_table)
bool insert_front_diffuse = (rsx_vertex_program.output_mask & 1);
bool insert_back_diffuse = (rsx_vertex_program.output_mask & 4);
bool insert_front_specular = (rsx_vertex_program.output_mask & 2);
bool insert_back_specular = (rsx_vertex_program.output_mask & 8);
bool front_back_diffuse = (insert_back_diffuse && insert_front_diffuse);
bool front_back_specular = (insert_back_specular && insert_front_specular);
for (auto &i : reg_table)
{
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", i.src_reg) && i.need_declare)
{
OS << "out vec4 " << i.name << ";" << std::endl;
if (i.name == "front_diff_color")
insert_front_diffuse = false;
if (i.name == "front_spec_color")
insert_front_specular = false;
std::string name = i.name;
if (front_back_diffuse && name == "diff_color")
name = "back_diff_color";
if (front_back_specular && name == "spec_color")
name = "back_spec_color";
OS << "out vec4 " << name << ";" << std::endl;
}
}
if (insert_back_diffuse && insert_front_diffuse)
OS << "out vec4 front_diff_color;" << std::endl;
if (insert_back_specular && insert_front_specular)
OS << "out vec4 front_spec_color;" << std::endl;
}
void add_input(std::stringstream & OS, const ParamItem &PI, const std::vector<rsx_vertex_input> &inputs)
@ -247,17 +276,34 @@ void GLVertexDecompilerThread::insertMainStart(std::stringstream & OS)
{
insert_glsl_legacy_function(OS);
OS << "void main()" << std::endl;
std::string parameters = "";
for (int i = 0; i < 16; ++i)
{
std::string reg_name = "dst_reg" + std::to_string(i);
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", reg_name))
{
if (parameters.length())
parameters += ", ";
parameters += "inout vec4 " + reg_name;
}
}
OS << "void vs_main(" << parameters << ")" << std::endl;
OS << "{" << std::endl;
// Declare inside main function
for (const ParamType& PT : m_parr.params[PF_PARAM_NONE])
//Declare temporary registers, ignoring those mapped to outputs
for (const ParamType PT : m_parr.params[PF_PARAM_NONE])
{
for (const ParamItem &PI : PT.items)
{
if (PI.name.substr(0, 7) == "dst_reg")
continue;
OS << " " << PT.type << " " << PI.name;
if (!PI.value.empty())
OS << " = " << PI.value;
OS << ";" << std::endl;
}
}
@ -282,10 +328,68 @@ void GLVertexDecompilerThread::insertMainStart(std::stringstream & OS)
void GLVertexDecompilerThread::insertMainEnd(std::stringstream & OS)
{
for (const auto &i : reg_table)
OS << "}" << std::endl << std::endl;
OS << "void main ()" << std::endl;
OS << "{" << std::endl;
std::string parameters = "";
if (ParamType *vec4Types = m_parr.SearchParam(PF_PARAM_NONE, "vec4"))
{
for (int i = 0; i < 16; ++i)
{
std::string reg_name = "dst_reg" + std::to_string(i);
for (auto &PI : vec4Types->items)
{
if (reg_name == PI.name)
{
if (parameters.length())
parameters += ", ";
parameters += reg_name;
OS << " vec4 " << reg_name;
if (!PI.value.empty())
OS << "= " << PI.value;
OS << ";" << std::endl;
}
}
}
}
OS << std::endl << " vs_main(" << parameters << ");" << std::endl << std::endl;
bool insert_front_diffuse = (rsx_vertex_program.output_mask & 1);
bool insert_front_specular = (rsx_vertex_program.output_mask & 2);
bool insert_back_diffuse = (rsx_vertex_program.output_mask & 4);
bool insert_back_specular = (rsx_vertex_program.output_mask & 8);
bool front_back_diffuse = (insert_back_diffuse && insert_front_diffuse);
bool front_back_specular = (insert_back_specular && insert_front_specular);
for (auto &i : reg_table)
{
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", i.src_reg))
OS << " " << i.name << " = " << i.src_reg << i.src_reg_mask << ";" << std::endl;
{
if (i.name == "front_diff_color")
insert_front_diffuse = false;
if (i.name == "front_spec_color")
insert_front_specular = false;
std::string name = i.name;
if (front_back_diffuse && name == "diff_color")
name = "back_diff_color";
if (front_back_specular && name == "spec_color")
name = "back_spec_color";
OS << " " << name << " = " << i.src_reg << i.src_reg_mask << ";" << std::endl;
}
}
for (const auto& uc : get_user_clip_planes(rsx_vertex_program))
@ -293,6 +397,14 @@ void GLVertexDecompilerThread::insertMainEnd(std::stringstream & OS)
OS << uc.second;
}
if (insert_back_diffuse && insert_front_diffuse)
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", "dst_reg1"))
OS << " front_diff_color = dst_reg1;\n";
if (insert_back_specular && insert_front_specular)
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", "dst_reg2"))
OS << " front_spec_color = dst_reg2;\n";
OS << " gl_Position = gl_Position * scaleOffsetMat;" << std::endl;
OS << "}" << std::endl;
}