gl/vk: Add constexpr to varying_registers and sync functions between the two backends

This commit is contained in:
scribam 2019-06-09 09:03:27 +02:00 committed by Ani
parent 497f0c26e7
commit c4667133c4
9 changed files with 51 additions and 61 deletions

View file

@ -1,13 +1,10 @@
#include "stdafx.h"
#include "GLCommonDecompiler.h"
namespace gl
{
int get_varying_register_location(const std::string &var_name)
{
static const std::pair<std::string, int> reg_table[] =
{
static constexpr std::array<std::pair<std::string_view, int>, 17> varying_registers =
{{
{"diff_color", 1},
{"spec_color", 2},
{"back_diff_color", 1},
@ -25,14 +22,18 @@ namespace gl
{"tc7", 13},
{"tc8", 14},
{"tc9", 15}
};
}};
for (const auto& v: reg_table)
int get_varying_register_location(std::string_view varying_register_name)
{
if (v.first == var_name)
return v.second;
for (const auto& varying_register : varying_registers)
{
if (varying_register.first == varying_register_name)
{
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);
}
}

View file

@ -1,10 +1,6 @@
#pragma once
#include "../Common/ShaderParam.h"
#include "../Common/GLSLCommon.h"
#include <ostream>
namespace gl
{
int get_varying_register_location(const std::string &var_name);
int get_varying_register_location(std::string_view varying_register_name);
}

View file

@ -6,7 +6,7 @@
#include "GLFragmentProgram.h"
#include "GLCommonDecompiler.h"
#include "../GCM.h"
#include "../Common/GLSLCommon.h"
std::string GLFragmentDecompilerThread::getFloatTypeName(size_t elementCount)
{

View file

@ -5,6 +5,7 @@
#include "GLCommonDecompiler.h"
#include "GLHelpers.h"
#include "../GCM.h"
#include "../Common/GLSLCommon.h"
#include <algorithm>

View file

@ -105,8 +105,8 @@ namespace vk
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 },
{ "tc1", 1 },
{ "tc2", 2 },
@ -125,17 +125,19 @@ namespace vk
{ "front_spec_color", 13 },
{ "fog_c", 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)
return t;
if (varying_register.first == varying_register_name)
{
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)

View file

@ -1,18 +1,11 @@
#pragma once
#include "../Common/ShaderParam.h"
#include "../Common/GLSLTypes.h"
namespace vk
{
using namespace ::glsl;
struct varying_register_t
{
std::string name;
int reg_location;
};
const varying_register_t& get_varying_register(const std::string& name);
int get_varying_register_location(std::string_view varying_register_name);
bool compile_glsl_to_spv(std::string& shader, program_domain domain, std::vector<u32> &spv);
void initialize_compiler_context();

View file

@ -1,5 +1,6 @@
#pragma once
#include "VKHelpers.h"
#include "Utilities/StrUtil.h"
#define VK_MAX_COMPUTE_TASKS 1024 // Max number of jobs per frame

View file

@ -54,7 +54,7 @@ void VKFragmentDecompilerThread::insertInputs(std::stringstream & OS)
//ssa is defined in the program body and is not a varying type
if (PI.name == "ssa") continue;
const vk::varying_register_t &reg = vk::get_varying_register(PI.name);
const auto reg_location = vk::get_varying_register_location(PI.name);
std::string var_name = PI.name;
if (two_sided_enabled)
@ -69,7 +69,7 @@ void VKFragmentDecompilerThread::insertInputs(std::stringstream & OS)
if (var_name == "fogc")
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.
if (m_prog.front_color_diffuse_output && m_prog.back_color_diffuse_output)
{
const vk::varying_register_t &reg = vk::get_varying_register("front_diff_color");
OS << "layout(location=" << reg.reg_location << ") in vec4 front_diff_color;\n";
OS << "layout(location=" << vk::get_varying_register_location("front_diff_color") << ") in vec4 front_diff_color;\n";
}
if (m_prog.front_color_specular_output && m_prog.back_color_specular_output)
{
const vk::varying_register_t &reg = vk::get_varying_register("front_spec_color");
OS << "layout(location=" << reg.reg_location << ") in vec4 front_spec_color;\n";
OS << "layout(location=" << vk::get_varying_register_location("front_spec_color") << ") in vec4 front_spec_color;\n";
}
}
}

View file

@ -171,8 +171,7 @@ void VKVertexDecompilerThread::insertOutputs(std::stringstream & OS, const std::
if (i.name == "front_spec_color")
insert_front_specular = false;
const vk::varying_register_t &reg = vk::get_varying_register(i.name);
OS << "layout(location=" << reg.reg_location << ") out vec4 " << i.name << ";\n";
OS << "layout(location=" << vk::get_varying_register_location(i.name) << ") out vec4 " << i.name << ";\n";
}
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
if (i.need_declare && (rsx_vertex_program.output_mask & i.check_mask_value) > 0)
{
const vk::varying_register_t &reg = vk::get_varying_register(i.name);
OS << "layout(location=" << reg.reg_location << ") out vec4 " << i.name << ";\n";
OS << "layout(location=" << vk::get_varying_register_location(i.name) << ") out vec4 " << i.name << ";\n";
}
}
}
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)
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)