rpcsx/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp

376 lines
9.3 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "Emu/System.h"
2013-11-09 22:29:49 +01:00
#include "GLVertexProgram.h"
#include "GLCommonDecompiler.h"
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
#include "../GCM.h"
2016-05-13 16:01:48 +02:00
#include <algorithm>
2015-05-19 19:43:22 +02:00
std::string GLVertexDecompilerThread::getFloatTypeName(size_t elementCount)
{
return getFloatTypeNameImpl(elementCount);
}
std::string GLVertexDecompilerThread::getIntTypeName(size_t elementCount)
{
return "ivec4";
}
2015-05-19 19:43:22 +02:00
std::string GLVertexDecompilerThread::getFunction(FUNCTION f)
{
return getFunctionImpl(f);
}
2015-05-19 19:43:22 +02:00
std::string GLVertexDecompilerThread::compareFunction(COMPARE f, const std::string &Op0, const std::string &Op1)
{
return compareFunctionImpl(f, Op0, Op1);
}
2015-05-19 19:43:22 +02:00
void GLVertexDecompilerThread::insertHeader(std::stringstream &OS)
{
OS << "#version 430" << std::endl << std::endl;
OS << "layout(std140, binding = 0) uniform ScaleOffsetBuffer" << std::endl;
OS << "{" << std::endl;
OS << " mat4 scaleOffsetMat;" << std::endl;
OS << " float fog_param0;\n";
OS << " float fog_param1;\n";
OS << " uint alpha_test;\n";
OS << " float alpha_ref;\n";
OS << "};" << std::endl;
}
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
std::vector<std::pair<std::string, std::string>> get_user_clip_planes(const RSXVertexProgram& prog)
{
std::vector<std::pair<std::string, std::string>> uc_planes;
if (prog.output_mask & (1 << 5))
{
if (prog.output_mask & CELL_GCM_ATTRIB_OUTPUT_MASK_UC0)
{
uc_planes.push_back({ "uniform int uc_m0 = 0;\n",
"\tgl_ClipDistance[0] = uc_m0 * dst_reg5.y;\n" });
}
if (prog.output_mask & CELL_GCM_ATTRIB_OUTPUT_MASK_UC1)
{
uc_planes.push_back({ "uniform int uc_m1 = 0;\n",
"\tgl_ClipDistance[1] = uc_m1 * dst_reg5.z;\n" });
}
if (prog.output_mask & CELL_GCM_ATTRIB_OUTPUT_MASK_UC2)
{
uc_planes.push_back({ "uniform int uc_m2 = 0;\n",
"\tgl_ClipDistance[2] = uc_m2 * dst_reg5.w;\n" });
}
}
if (prog.output_mask & (1 << 6))
{
if (prog.output_mask & CELL_GCM_ATTRIB_OUTPUT_MASK_UC3)
{
uc_planes.push_back({ "uniform int uc_m3 = 0;\n",
"\tgl_ClipDistance[3] = uc_m3 * dst_reg6.y;\n" });
}
if (prog.output_mask & CELL_GCM_ATTRIB_OUTPUT_MASK_UC4)
{
uc_planes.push_back({ "uniform int uc_m4 = 0;\n",
"\tgl_ClipDistance[4] = uc_m4 * dst_reg6.z;\n" });
}
if (prog.output_mask & CELL_GCM_ATTRIB_OUTPUT_MASK_UC5)
{
uc_planes.push_back({ "uniform int uc_m5 = 0;\n",
"\tgl_ClipDistance[5] = uc_m5 * dst_reg6.w;\n" });
}
}
return uc_planes;
}
2015-05-19 19:43:22 +02:00
void GLVertexDecompilerThread::insertInputs(std::stringstream & OS, const std::vector<ParamType>& inputs)
{
std::vector<std::tuple<size_t, std::string>> input_data;
for (const ParamType &PT : inputs)
{
2015-05-19 19:43:22 +02:00
for (const ParamItem &PI : PT.items)
{
input_data.push_back(std::make_tuple(PI.location, PI.name));
}
}
/**
* Its is important that the locations are in the order that vertex attributes are expected.
* If order is not adhered to, channels may be swapped leading to corruption
*/
std::sort(input_data.begin(), input_data.end());
int location = 1;
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
for (const std::tuple<size_t, std::string>& item : input_data)
{
for (const ParamType &PT : inputs)
{
for (const ParamItem &PI : PT.items)
{
if (PI.name == std::get<1>(item))
{
bool is_int = false;
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
for (const auto &attrib : rsx_vertex_program.rsx_vertex_inputs)
{
if (attrib.location == std::get<0>(item))
{
if (attrib.int_type) is_int = true;
break;
}
}
std::string samplerType = is_int ? "isamplerBuffer" : "samplerBuffer";
OS << "layout(location=" << location++ << ")" << " uniform " << samplerType << " " << PI.name << "_buffer;" << std::endl;
}
}
}
2015-05-19 19:43:22 +02:00
}
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
for (const auto& uc : get_user_clip_planes(rsx_vertex_program))
{
OS << uc.first;
}
}
2015-05-19 19:43:22 +02:00
void GLVertexDecompilerThread::insertConstants(std::stringstream & OS, const std::vector<ParamType> & constants)
{
OS << "layout(std140, binding = 1) uniform VertexConstantsBuffer" << std::endl;
OS << "{" << std::endl;
OS << " vec4 vc[468];" << std::endl;
OS << "};" << std::endl << std::endl;
for (const ParamType &PT: constants)
{
for (const ParamItem &PI : PT.items)
{
if (PI.name == "vc[468]")
continue;
OS << "uniform " << PT.type << " " << PI.name << ";" << std::endl;
}
}
}
2015-05-19 19:43:22 +02:00
struct reg_info
{
2015-05-19 19:43:22 +02:00
std::string name;
bool need_declare;
std::string src_reg;
std::string src_reg_mask;
bool need_cast;
};
static const reg_info reg_table[] =
{
2015-05-19 19:43:22 +02:00
{ "gl_Position", false, "dst_reg0", "", false },
{ "diff_color", true, "dst_reg1", "", false },
{ "spec_color", true, "dst_reg2", "", false },
{ "front_diff_color", true, "dst_reg3", "", false },
{ "front_spec_color", true, "dst_reg4", "", false },
{ "fog_c", true, "dst_reg5", ".xxxx", true },
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
//{ "gl_ClipDistance[0]", false, "dst_reg5", ".y", false },
//{ "gl_ClipDistance[1]", false, "dst_reg5", ".z", false },
//{ "gl_ClipDistance[2]", false, "dst_reg5", ".w", false },
2015-05-19 19:43:22 +02:00
{ "gl_PointSize", false, "dst_reg6", ".x", false },
//Disable user clip planes until they are properly handled
//{ "gl_ClipDistance[3]", false, "dst_reg6", ".y", false },
//{ "gl_ClipDistance[4]", false, "dst_reg6", ".z", false },
//{ "gl_ClipDistance[5]", false, "dst_reg6", ".w", false },
2015-05-19 19:43:22 +02:00
{ "tc0", true, "dst_reg7", "", false },
{ "tc1", true, "dst_reg8", "", false },
{ "tc2", true, "dst_reg9", "", false },
{ "tc3", true, "dst_reg10", "", false },
{ "tc4", true, "dst_reg11", "", false },
{ "tc5", true, "dst_reg12", "", false },
{ "tc6", true, "dst_reg13", "", false },
{ "tc7", true, "dst_reg14", "", false },
{ "tc8", true, "dst_reg15", "", false },
{ "tc9", true, "dst_reg6", "", false } // In this line, dst_reg6 is correct since dst_reg goes from 0 to 15.
};
void GLVertexDecompilerThread::insertOutputs(std::stringstream & OS, const std::vector<ParamType> & outputs)
{
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
for (const auto &i : reg_table)
2015-05-19 19:43:22 +02:00
{
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", i.src_reg) && i.need_declare)
{
OS << "out vec4 " << i.name << ";" << std::endl;
}
2015-05-19 19:43:22 +02:00
}
}
void add_input(std::stringstream & OS, const ParamItem &PI, const std::vector<rsx_vertex_input> &inputs)
{
for (const auto &real_input : inputs)
{
if (real_input.location != PI.location)
continue;
std::string vecType = " vec4 ";
if (real_input.int_type)
vecType = " ivec4 ";
if (!real_input.is_array)
{
OS << vecType << PI.name << " = texelFetch(" << PI.name << "_buffer, 0);" << std::endl;
return;
}
if (real_input.frequency > 1)
{
if (real_input.is_modulo)
{
OS << vecType << PI.name << "= texelFetch(" << PI.name << "_buffer, gl_VertexID %" << real_input.frequency << ");" << std::endl;
return;
}
OS << vecType << PI.name << "= texelFetch(" << PI.name << "_buffer, gl_VertexID /" << real_input.frequency << ");" << std::endl;
return;
}
OS << vecType << PI.name << "= texelFetch(" << PI.name << "_buffer, gl_VertexID).rgba;" << std::endl;
return;
}
OS << " vec4 " << PI.name << "= texelFetch(" << PI.name << "_buffer, gl_VertexID).rgba;" << std::endl;
}
2015-05-19 19:43:22 +02:00
void GLVertexDecompilerThread::insertMainStart(std::stringstream & OS)
{
insert_glsl_legacy_function(OS);
2015-05-19 19:43:22 +02:00
OS << "void main()" << std::endl;
OS << "{" << std::endl;
2015-05-19 19:43:22 +02:00
// Declare inside main function
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
for (const ParamType& PT : m_parr.params[PF_PARAM_NONE])
{
2015-05-19 19:43:22 +02:00
for (const ParamItem &PI : PT.items)
{
2015-05-19 19:43:22 +02:00
OS << " " << PT.type << " " << PI.name;
if (!PI.value.empty())
OS << " = " << PI.value;
OS << ";" << std::endl;
}
}
for (const ParamType &PT : m_parr.params[PF_PARAM_IN])
{
for (const ParamItem &PI : PT.items)
add_input(OS, PI, rsx_vertex_program.rsx_vertex_inputs);
}
for (const ParamType &PT : m_parr.params[PF_PARAM_UNIFORM])
{
if (PT.type == "sampler2D")
{
for (const ParamItem &PI : PT.items)
{
OS << " vec2 " << PI.name << "_coord_scale = vec2(1.);" << std::endl;
}
}
}
}
2015-05-19 19:43:22 +02:00
void GLVertexDecompilerThread::insertMainEnd(std::stringstream & OS)
{
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
for (const auto &i : reg_table)
{
2015-05-19 19:43:22 +02:00
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", i.src_reg))
OS << " " << i.name << " = " << i.src_reg << i.src_reg_mask << ";" << std::endl;
}
Porting of DH's user clip implementation in gl (#2139) * Porting of DH's user clip implementation in gl * Tweak clang-format * rsx: Move inline array to draw_clause structure. * rsx: Use variant based draw commands. * rsx: Dump DRAW_ARRAYS and DRAW_INDEX_ARRAYS. * GL: old recompiler clean up (#2142) * RSX texture refactor (#2144) * gl/vk: Enable vertex texture fetch (#2127) * gl: Enable vertex textures * rsx: use textureLod instead of generic texture sample * rsx: handle uploading of W32_X32_Y32_Z32 * gl: Re-enable proper shader logging remove old logging method that overwrites single file * gl: Declare texture_coord_scale for vertex samplers * gl: texture remap fixes; enable remap for vertex textures * gl: offset texture indices to base layer 16 * rsx: Fix W32_Z32_Y32_X32_FLOAT subresource layout * vk: Enable vertex textures * rsx: define special calls for vertex texture fetch * gl: improved vertex texture fetch setup * vk: Fix texture formats and component mapping * vk: Implement vertex texture fetch functions properly * vk/gl: proper fix for primitive restart index revert inadvertent decompiler update * gl: Disable filtering for vertex textures * Hopefully fix appveyor build (#2148) * GL/Vulkan: Bug fixes and improvements; alphakill for vulkan (#2146) * vk: Zero-initialize some more structs * gl: Clean up fragment program generation code * vk: Enable alpha kill * vk: Fix surface clear; redirect output for surface_type:b * vk: Tie renderpass to program object to avoid incompatible passes * vk: Properly compute descriptor pool size (#2150) * rsx: Set default attribute format to float. * rsx: vertex attribute size is 1 again for CMP, let backend handles this formats properties. * rsx: Move printing function in a separate header/cpp * Porting of DH's user clip implementation in gl
2016-09-24 12:21:41 +02:00
for (const auto& uc : get_user_clip_planes(rsx_vertex_program))
{
OS << uc.second;
}
2015-05-19 19:43:22 +02:00
OS << " gl_Position = gl_Position * scaleOffsetMat;" << std::endl;
OS << "}" << std::endl;
}
2015-05-19 19:43:22 +02:00
2013-11-09 22:29:49 +01:00
void GLVertexDecompilerThread::Task()
{
2015-05-19 19:43:22 +02:00
m_shader = Decompile();
}
2013-11-09 22:29:49 +01:00
GLVertexProgram::GLVertexProgram()
{
}
2013-11-09 22:29:49 +01:00
GLVertexProgram::~GLVertexProgram()
{
Delete();
}
void GLVertexProgram::Decompile(const RSXVertexProgram& prog)
{
GLVertexDecompilerThread decompiler(prog, shader, parr);
2014-06-11 22:22:32 +02:00
decompiler.Task();
}
2013-11-09 22:29:49 +01:00
void GLVertexProgram::Compile()
{
2015-05-16 01:10:27 +02:00
if (id)
2014-12-28 23:42:08 +01:00
{
glDeleteShader(id);
}
id = glCreateShader(GL_VERTEX_SHADER);
const char* str = shader.c_str();
const int strlen = ::narrow<int>(shader.length());
fs::create_path(fs::get_config_dir() + "/shaderlog");
fs::file(fs::get_config_dir() + "shaderlog/VertexProgram" + std::to_string(id) + ".glsl", fs::rewrite).write(str);
glShaderSource(id, 1, &str, &strlen);
glCompileShader(id);
GLint r = GL_FALSE;
glGetShaderiv(id, GL_COMPILE_STATUS, &r);
if (r != GL_TRUE)
{
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &r);
if (r)
{
char* buf = new char[r + 1]();
GLsizei len;
glGetShaderInfoLog(id, r, &len, buf);
LOG_ERROR(RSX, "Failed to compile vertex shader: %s", buf);
delete[] buf;
}
LOG_NOTICE(RSX, "%s", shader.c_str());
Emu.Pause();
}
}
2013-11-09 22:29:49 +01:00
void GLVertexProgram::Delete()
{
shader.clear();
if (id)
{
2014-06-19 22:34:09 +02:00
if (Emu.IsStopped())
{
LOG_WARNING(RSX, "GLVertexProgram::Delete(): glDeleteShader(%d) avoided", id);
2014-06-19 22:34:09 +02:00
}
else
{
glDeleteShader(id);
}
id = 0;
}
}