Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsx/utilities: add some constexpr #6065

Merged
merged 4 commits into from Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions Utilities/geometry.h
Expand Up @@ -841,34 +841,34 @@ struct color4_base
T xyzw[4];
};

color4_base()
constexpr color4_base()
: x{}
, y{}
, z{}
, w{ T(1) }
{
}

color4_base(T x, T y = {}, T z = {}, T w = {})
constexpr color4_base(T x, T y = {}, T z = {}, T w = {})
: x(x)
, y(y)
, z(z)
, w(w)
{
}

bool operator == (const color4_base& rhs) const
constexpr bool operator == (const color4_base& rhs) const
{
return r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a;
}

bool operator != (const color4_base& rhs) const
constexpr bool operator != (const color4_base& rhs) const
{
return !(*this == rhs);
}

template<typename NT>
operator color4_base<NT>() const
constexpr operator color4_base<NT>() const
{
return{ (NT)x, (NT)y, (NT)z, (NT)w };
}
Expand Down
55 changes: 28 additions & 27 deletions rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp
@@ -1,38 +1,39 @@
#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[] =
{
{ "diff_color", 1 },
{ "spec_color", 2 },
{ "back_diff_color", 1 },
{ "back_spec_color", 2 },
{ "front_diff_color", 3 },
{ "front_spec_color", 4 },
{ "fog_c", 5 },
{ "tc0", 6 },
{ "tc1", 7 },
{ "tc2", 8 },
{ "tc3", 9 },
{ "tc4", 10 },
{ "tc5", 11 },
{ "tc6", 12 },
{ "tc7", 13 },
{ "tc8", 14 },
{ "tc9", 15 }
};
static constexpr std::array<std::pair<std::string_view, int>, 17> varying_registers =
{{
{"diff_color", 1},
{"spec_color", 2},
{"back_diff_color", 1},
{"back_spec_color", 2},
{"front_diff_color", 3},
{"front_spec_color", 4},
{"fog_c", 5},
{"tc0", 6},
{"tc1", 7},
{"tc2", 8},
{"tc3", 9},
{"tc4", 10},
{"tc5", 11},
{"tc6", 12},
{"tc7", 13},
{"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)
return v.second;
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);
}
}
6 changes: 1 addition & 5 deletions rpcs3/Emu/RSX/GL/GLCommonDecompiler.h
@@ -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);
}
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp
Expand Up @@ -6,7 +6,7 @@
#include "GLFragmentProgram.h"
#include "GLCommonDecompiler.h"
#include "../GCM.h"

#include "../Common/GLSLCommon.h"

std::string GLFragmentDecompilerThread::getFloatTypeName(size_t elementCount)
{
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/RSX/GL/GLVertexProgram.cpp
Expand Up @@ -5,6 +5,7 @@
#include "GLCommonDecompiler.h"
#include "GLHelpers.h"
#include "../GCM.h"
#include "../Common/GLSLCommon.h"

#include <algorithm>

Expand Down
31 changes: 1 addition & 30 deletions rpcs3/Emu/RSX/RSXFIFO.cpp
Expand Up @@ -4,12 +4,6 @@
#include "RSXThread.h"
#include "Capture/rsx_capture.h"

extern rsx::frame_capture_data frame_capture;
extern bool user_asked_for_frame_capture;
extern bool capture_current_frame;

#define ENABLE_OPTIMIZATION_DEBUGGING 0

namespace rsx
{
namespace FIFO
Expand Down Expand Up @@ -185,28 +179,6 @@ namespace rsx
data.set(cmd & 0xfffc, vm::read32(m_args_ptr));
}

flattening_helper::flattening_helper()
{
const std::pair<u32, u32> ignorable_ranges[] =
{
// General
{ NV4097_INVALIDATE_VERTEX_FILE, 3 }, // PSLight clears VERTEX_FILE[0-2]
{ NV4097_INVALIDATE_VERTEX_CACHE_FILE, 1 },
{ NV4097_INVALIDATE_L2, 1 },
{ NV4097_INVALIDATE_ZCULL, 1 }
};

std::fill(m_register_properties.begin(), m_register_properties.end(), 0u);

for (const auto &method : ignorable_ranges)
{
for (u32 i = 0; i < method.second; ++i)
{
m_register_properties[method.first + i] |= register_props::always_ignore;
}
}
}

void flattening_helper::reset(bool _enabled)
{
enabled = _enabled;
Expand Down Expand Up @@ -336,8 +308,7 @@ namespace rsx
{
if (UNLIKELY(draw_count))
{
const auto props = m_register_properties[reg];
if (UNLIKELY(props & register_props::always_ignore))
if (UNLIKELY(m_register_properties[reg] & register_props::always_ignore))
{
// Always ignore
command.reg = FIFO_DISABLED_COMMAND;
Expand Down
45 changes: 29 additions & 16 deletions rpcs3/Emu/RSX/RSXFIFO.h
Expand Up @@ -2,23 +2,10 @@

#include <Utilities/types.h>
#include <Utilities/Atomic.h>
#include <Utilities/mutex.h>
#include <Utilities/Thread.h>

#include "rsx_utils.h"
#include "Emu/Cell/lv2/sys_rsx.h"

#include <vector>
#include <string>
#include <memory>
#include <unordered_map>

#ifndef __unused
#define __unused(expression) do { (void)(expression); } while(0)
#endif

struct RsxDmaControl;

namespace rsx
{
class thread;
Expand Down Expand Up @@ -72,7 +59,33 @@ namespace rsx
application_not_compatible
};

std::array<u8, 0x10000 / 4> m_register_properties;
// Workaround for MSVC, C2248
static constexpr u8 register_props_always_ignore = register_props::always_ignore;

static constexpr std::array<u8, 0x10000 / 4> m_register_properties = []
{
constexpr std::array<std::pair<u32, u32>, 4> ignorable_ranges =
{{
// General
{ NV4097_INVALIDATE_VERTEX_FILE, 3 }, // PSLight clears VERTEX_FILE[0-2]
{ NV4097_INVALIDATE_VERTEX_CACHE_FILE, 1 },
{ NV4097_INVALIDATE_L2, 1 },
{ NV4097_INVALIDATE_ZCULL, 1 }
}};

std::array<u8, 0x10000 / 4> register_properties{};

for (const auto &method : ignorable_ranges)
{
for (u32 i = 0; i < method.second; ++i)
{
register_properties[method.first + i] |= register_props_always_ignore;
}
}

return register_properties;
}();

u32 deferred_primitive = 0;
u32 draw_count = 0;
u32 begin_end_ctr = 0;
Expand All @@ -84,8 +97,8 @@ namespace rsx
void reset(bool _enabled);

public:
flattening_helper();
~flattening_helper() {}
flattening_helper() = default;
~flattening_helper() = default;

u32 get_primitive() const { return deferred_primitive; }
bool is_enabled() const { return enabled; }
Expand Down
18 changes: 10 additions & 8 deletions rpcs3/Emu/RSX/VK/VKCommonDecompiler.cpp
Expand Up @@ -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 },
Expand All @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions rpcs3/Emu/RSX/VK/VKCommonDecompiler.h
@@ -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();
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/RSX/VK/VKCompute.h
@@ -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

Expand Down
10 changes: 4 additions & 6 deletions rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp
Expand Up @@ -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)
Expand All @@ -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";
}
}

Expand All @@ -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";
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions rpcs3/Emu/RSX/VK/VKVertexProgram.cpp
Expand Up @@ -171,26 +171,24 @@ 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
{
//Force some outputs to be declared even if unused so we can set default values
//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)
Expand Down