mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-13 18:28:35 +12:00
gl/vk: Add constexpr to varying_registers and sync functions between the two backends
This commit is contained in:
parent
497f0c26e7
commit
c4667133c4
9 changed files with 51 additions and 61 deletions
|
@ -1,38 +1,39 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "GLCommonDecompiler.h"
|
#include "GLCommonDecompiler.h"
|
||||||
|
|
||||||
|
|
||||||
namespace gl
|
namespace gl
|
||||||
{
|
{
|
||||||
int get_varying_register_location(const std::string &var_name)
|
static constexpr std::array<std::pair<std::string_view, int>, 17> varying_registers =
|
||||||
{
|
{{
|
||||||
static const std::pair<std::string, int> reg_table[] =
|
{"diff_color", 1},
|
||||||
{
|
{"spec_color", 2},
|
||||||
{ "diff_color", 1 },
|
{"back_diff_color", 1},
|
||||||
{ "spec_color", 2 },
|
{"back_spec_color", 2},
|
||||||
{ "back_diff_color", 1 },
|
{"front_diff_color", 3},
|
||||||
{ "back_spec_color", 2 },
|
{"front_spec_color", 4},
|
||||||
{ "front_diff_color", 3 },
|
{"fog_c", 5},
|
||||||
{ "front_spec_color", 4 },
|
{"tc0", 6},
|
||||||
{ "fog_c", 5 },
|
{"tc1", 7},
|
||||||
{ "tc0", 6 },
|
{"tc2", 8},
|
||||||
{ "tc1", 7 },
|
{"tc3", 9},
|
||||||
{ "tc2", 8 },
|
{"tc4", 10},
|
||||||
{ "tc3", 9 },
|
{"tc5", 11},
|
||||||
{ "tc4", 10 },
|
{"tc6", 12},
|
||||||
{ "tc5", 11 },
|
{"tc7", 13},
|
||||||
{ "tc6", 12 },
|
{"tc8", 14},
|
||||||
{ "tc7", 13 },
|
{"tc9", 15}
|
||||||
{ "tc8", 14 },
|
}};
|
||||||
{ "tc9", 15 }
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const auto& v: reg_table)
|
int get_varying_register_location(std::string_view varying_register_name)
|
||||||
|
{
|
||||||
|
for (const auto& varying_register : varying_registers)
|
||||||
{
|
{
|
||||||
if (v.first == var_name)
|
if (varying_register.first == varying_register_name)
|
||||||
return v.second;
|
{
|
||||||
|
return varying_register.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::throw_exception("register named %s should not be declared!", var_name.c_str());
|
fmt::throw_exception("Unknown register name: %s" HERE, varying_register_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../Common/ShaderParam.h"
|
|
||||||
#include "../Common/GLSLCommon.h"
|
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
namespace gl
|
namespace gl
|
||||||
{
|
{
|
||||||
int get_varying_register_location(const std::string &var_name);
|
int get_varying_register_location(std::string_view varying_register_name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "GLFragmentProgram.h"
|
#include "GLFragmentProgram.h"
|
||||||
#include "GLCommonDecompiler.h"
|
#include "GLCommonDecompiler.h"
|
||||||
#include "../GCM.h"
|
#include "../GCM.h"
|
||||||
|
#include "../Common/GLSLCommon.h"
|
||||||
|
|
||||||
std::string GLFragmentDecompilerThread::getFloatTypeName(size_t elementCount)
|
std::string GLFragmentDecompilerThread::getFloatTypeName(size_t elementCount)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "GLCommonDecompiler.h"
|
#include "GLCommonDecompiler.h"
|
||||||
#include "GLHelpers.h"
|
#include "GLHelpers.h"
|
||||||
#include "../GCM.h"
|
#include "../GCM.h"
|
||||||
|
#include "../Common/GLSLCommon.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,8 @@ namespace vk
|
||||||
rsc.limits.generalConstantMatrixVectorIndexing = 1;
|
rsc.limits.generalConstantMatrixVectorIndexing = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const varying_register_t varying_regs[] =
|
static constexpr std::array<std::pair<std::string_view, int>, 18> varying_registers =
|
||||||
{
|
{{
|
||||||
{ "tc0", 0 },
|
{ "tc0", 0 },
|
||||||
{ "tc1", 1 },
|
{ "tc1", 1 },
|
||||||
{ "tc2", 2 },
|
{ "tc2", 2 },
|
||||||
|
@ -125,17 +125,19 @@ namespace vk
|
||||||
{ "front_spec_color", 13 },
|
{ "front_spec_color", 13 },
|
||||||
{ "fog_c", 14 },
|
{ "fog_c", 14 },
|
||||||
{ "fogc", 14 }
|
{ "fogc", 14 }
|
||||||
};
|
}};
|
||||||
|
|
||||||
const varying_register_t & get_varying_register(const std::string & name)
|
int get_varying_register_location(std::string_view varying_register_name)
|
||||||
{
|
{
|
||||||
for (const auto&t : varying_regs)
|
for (const auto& varying_register : varying_registers)
|
||||||
{
|
{
|
||||||
if (t.name == name)
|
if (varying_register.first == varying_register_name)
|
||||||
return t;
|
{
|
||||||
|
return varying_register.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::throw_exception("Unknown register name: %s" HERE, name);
|
fmt::throw_exception("Unknown register name: %s" HERE, varying_register_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compile_glsl_to_spv(std::string& shader, program_domain domain, std::vector<u32>& spv)
|
bool compile_glsl_to_spv(std::string& shader, program_domain domain, std::vector<u32>& spv)
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../Common/ShaderParam.h"
|
|
||||||
#include "../Common/GLSLTypes.h"
|
#include "../Common/GLSLTypes.h"
|
||||||
|
|
||||||
namespace vk
|
namespace vk
|
||||||
{
|
{
|
||||||
using namespace ::glsl;
|
using namespace ::glsl;
|
||||||
|
|
||||||
struct varying_register_t
|
int get_varying_register_location(std::string_view varying_register_name);
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
int reg_location;
|
|
||||||
};
|
|
||||||
|
|
||||||
const varying_register_t& get_varying_register(const std::string& name);
|
|
||||||
bool compile_glsl_to_spv(std::string& shader, program_domain domain, std::vector<u32> &spv);
|
bool compile_glsl_to_spv(std::string& shader, program_domain domain, std::vector<u32> &spv);
|
||||||
|
|
||||||
void initialize_compiler_context();
|
void initialize_compiler_context();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "VKHelpers.h"
|
#include "VKHelpers.h"
|
||||||
|
#include "Utilities/StrUtil.h"
|
||||||
|
|
||||||
#define VK_MAX_COMPUTE_TASKS 1024 // Max number of jobs per frame
|
#define VK_MAX_COMPUTE_TASKS 1024 // Max number of jobs per frame
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ void VKFragmentDecompilerThread::insertInputs(std::stringstream & OS)
|
||||||
//ssa is defined in the program body and is not a varying type
|
//ssa is defined in the program body and is not a varying type
|
||||||
if (PI.name == "ssa") continue;
|
if (PI.name == "ssa") continue;
|
||||||
|
|
||||||
const vk::varying_register_t ® = vk::get_varying_register(PI.name);
|
const auto reg_location = vk::get_varying_register_location(PI.name);
|
||||||
std::string var_name = PI.name;
|
std::string var_name = PI.name;
|
||||||
|
|
||||||
if (two_sided_enabled)
|
if (two_sided_enabled)
|
||||||
|
@ -69,7 +69,7 @@ void VKFragmentDecompilerThread::insertInputs(std::stringstream & OS)
|
||||||
if (var_name == "fogc")
|
if (var_name == "fogc")
|
||||||
var_name = "fog_c";
|
var_name = "fog_c";
|
||||||
|
|
||||||
OS << "layout(location=" << reg.reg_location << ") in " << PT.type << " " << var_name << ";\n";
|
OS << "layout(location=" << reg_location << ") in " << PT.type << " " << var_name << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,14 +78,12 @@ void VKFragmentDecompilerThread::insertInputs(std::stringstream & OS)
|
||||||
//Only include the front counterparts if the default output is for back only and exists.
|
//Only include the front counterparts if the default output is for back only and exists.
|
||||||
if (m_prog.front_color_diffuse_output && m_prog.back_color_diffuse_output)
|
if (m_prog.front_color_diffuse_output && m_prog.back_color_diffuse_output)
|
||||||
{
|
{
|
||||||
const vk::varying_register_t ® = vk::get_varying_register("front_diff_color");
|
OS << "layout(location=" << vk::get_varying_register_location("front_diff_color") << ") in vec4 front_diff_color;\n";
|
||||||
OS << "layout(location=" << reg.reg_location << ") in vec4 front_diff_color;\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_prog.front_color_specular_output && m_prog.back_color_specular_output)
|
if (m_prog.front_color_specular_output && m_prog.back_color_specular_output)
|
||||||
{
|
{
|
||||||
const vk::varying_register_t ® = vk::get_varying_register("front_spec_color");
|
OS << "layout(location=" << vk::get_varying_register_location("front_spec_color") << ") in vec4 front_spec_color;\n";
|
||||||
OS << "layout(location=" << reg.reg_location << ") in vec4 front_spec_color;\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,8 +171,7 @@ void VKVertexDecompilerThread::insertOutputs(std::stringstream & OS, const std::
|
||||||
if (i.name == "front_spec_color")
|
if (i.name == "front_spec_color")
|
||||||
insert_front_specular = false;
|
insert_front_specular = false;
|
||||||
|
|
||||||
const vk::varying_register_t ® = vk::get_varying_register(i.name);
|
OS << "layout(location=" << vk::get_varying_register_location(i.name) << ") out vec4 " << i.name << ";\n";
|
||||||
OS << "layout(location=" << reg.reg_location << ") out vec4 " << i.name << ";\n";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -180,17 +179,16 @@ void VKVertexDecompilerThread::insertOutputs(std::stringstream & OS, const std::
|
||||||
//NOTE: Registers that can be skept will not have their check_mask_value set
|
//NOTE: Registers that can be skept will not have their check_mask_value set
|
||||||
if (i.need_declare && (rsx_vertex_program.output_mask & i.check_mask_value) > 0)
|
if (i.need_declare && (rsx_vertex_program.output_mask & i.check_mask_value) > 0)
|
||||||
{
|
{
|
||||||
const vk::varying_register_t ® = vk::get_varying_register(i.name);
|
OS << "layout(location=" << vk::get_varying_register_location(i.name) << ") out vec4 " << i.name << ";\n";
|
||||||
OS << "layout(location=" << reg.reg_location << ") out vec4 " << i.name << ";\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insert_back_diffuse && insert_front_diffuse)
|
if (insert_back_diffuse && insert_front_diffuse)
|
||||||
OS << "layout(location=" << vk::get_varying_register("front_diff_color").reg_location << ") out vec4 front_diff_color;\n";
|
OS << "layout(location=" << vk::get_varying_register_location("front_diff_color") << ") out vec4 front_diff_color;\n";
|
||||||
|
|
||||||
if (insert_back_specular && insert_front_specular)
|
if (insert_back_specular && insert_front_specular)
|
||||||
OS << "layout(location=" << vk::get_varying_register("front_spec_color").reg_location << ") out vec4 front_spec_color;\n";
|
OS << "layout(location=" << vk::get_varying_register_location("front_spec_color") << ") out vec4 front_spec_color;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKVertexDecompilerThread::insertMainStart(std::stringstream & OS)
|
void VKVertexDecompilerThread::insertMainStart(std::stringstream & OS)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue