rsx: Fix shader compilation

This commit is contained in:
kd-11 2022-12-10 18:20:43 +03:00 committed by kd-11
parent a0ef1a672c
commit 9c0b2338cf
5 changed files with 22 additions and 16 deletions

View File

@ -50,7 +50,7 @@ void GLFragmentDecompilerThread::insertInputs(std::stringstream & OS)
{
glsl::insert_fragment_shader_inputs_block(
OS,
glsl::extension_type::NV,
glsl::extension_flavour::NV,
m_prog,
m_parr.params[PF_PARAM_IN],
{

View File

@ -1145,6 +1145,7 @@ namespace glsl
void insert_fragment_shader_inputs_block(
std::stringstream& OS,
const std::string_view ext_flavour,
const RSXFragmentProgram& prog,
const std::vector<ParamType>& params,
const two_sided_lighting_config& _2sided_lighting,
@ -1157,7 +1158,7 @@ namespace glsl
std::string type;
};
rsx::simple_array<_varying_register_config> varying_list;
std::vector<_varying_register_config> varying_list;
for (const ParamType& PT : params)
{
@ -1208,7 +1209,7 @@ namespace glsl
}
// Make the output a little nicer
varying_list.sort(FN(x.location < y.location));
std::sort(varying_list.begin(), varying_list.end(), FN(x.location < y.location));
if (!(prog.ctrl & RSX_SHADER_CONTROL_ATTRIBUTE_INTERPOLATION))
{
@ -1217,22 +1218,27 @@ namespace glsl
OS << "layout(location=" << reg.location << ") in " << reg.type << " " << reg.name << ";\n";
}
OS << "\n";
return;
}
for (const auto& reg : varying_list)
{
OS << "layout(location=" << reg.location << ") pervertexNV in " << reg.type << " " << reg.name << "_raw[3];\n";
OS << "layout(location=" << reg.location << ") pervertex" << ext_flavour << " in " << reg.type << " " << reg.name << "_raw[3];\n";
}
// Interpolate the input attributes manually.
// Matches AMD behavior where gl_BaryCoordSmoothAMD only provides x and y with z being autogenerated.
OS <<
"vec4 _interpolate_varying3(const in vec4[3] v)\n"
"{\n"
" const BaryCoord_z = 1.0 - (gl_BaryCoordNV.x + gl_BaryCoordNV.y);\n"
" return gl_BaryCoordNV.x * v[0] + gl_BaryCoordNV.y * v[1] + BaryCoord_z * v[2];\n"
"}\n\n";
OS << fmt::replace_all(
"\n"
"vec4 _interpolate_varying3(const in vec4[3] v)\n"
"{\n"
" const float _gl_BaryCoord_z = 1.0 - ($gl_BaryCoord.x + $gl_BaryCoord.y);\n"
" return $gl_BaryCoord.x * v[0] + $gl_BaryCoord.y * v[1] + _gl_BaryCoord_z * v[2];\n"
"}\n\n",
{
{ "$gl_BaryCoord", "gl_BaryCoord"s + std::string(ext_flavour) }
});
for (const auto& reg : varying_list)
{

View File

@ -4,7 +4,7 @@
#include "GLSLTypes.h"
#include "ShaderParam.h"
class RSXFragmentProgram;
struct RSXFragmentProgram;
namespace rsx
{
@ -90,7 +90,7 @@ namespace glsl
bool two_sided_specular;
};
struct extension_type
struct extension_flavour
{
static constexpr std::string_view
EXT = "EXT",

View File

@ -65,7 +65,7 @@ void VKFragmentDecompilerThread::insertInputs(std::stringstream & OS)
{
glsl::insert_fragment_shader_inputs_block(
OS,
glsl::extension_type::EXT,
glsl::extension_flavour::EXT,
m_prog,
m_parr.params[PF_PARAM_IN],
{

View File

@ -541,9 +541,9 @@ VKGSRender::VKGSRender(utils::serial* ar) noexcept : GSRender(ar)
// NVIDIA has broken attribute interpolation
backend_config.supports_normalized_barycentrics = (
vk::get_driver_vendor() != vk::driver_vendor::NVIDIA &&
m_device->get_barycoords_support() &&
g_cfg.video.shader_precision != gpu_preset_level::low);
vk::get_driver_vendor() != vk::driver_vendor::NVIDIA ||
!m_device->get_barycoords_support() ||
g_cfg.video.shader_precision == gpu_preset_level::low);
// NOTE: We do not actually need multiple sample support for A2C to work
// This is here for visual consistency - will be removed when AA problems due to mipmaps are fixed