From 59c337ac2b17125c085d6dda98db2bc20bb78eae Mon Sep 17 00:00:00 2001 From: scribam Date: Sun, 2 Jun 2019 19:51:25 +0200 Subject: [PATCH 1/3] rsx: Use constexpr for flattening_helper::m_register_properties --- rpcs3/Emu/RSX/RSXFIFO.cpp | 31 +-------------------------- rpcs3/Emu/RSX/RSXFIFO.h | 45 +++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 46 deletions(-) diff --git a/rpcs3/Emu/RSX/RSXFIFO.cpp b/rpcs3/Emu/RSX/RSXFIFO.cpp index 8849bd10bb1f..a357432ca63b 100644 --- a/rpcs3/Emu/RSX/RSXFIFO.cpp +++ b/rpcs3/Emu/RSX/RSXFIFO.cpp @@ -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 @@ -185,28 +179,6 @@ namespace rsx data.set(cmd & 0xfffc, vm::read32(m_args_ptr)); } - flattening_helper::flattening_helper() - { - const std::pair 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; @@ -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; diff --git a/rpcs3/Emu/RSX/RSXFIFO.h b/rpcs3/Emu/RSX/RSXFIFO.h index 3bae4d3d5db6..a32b0e47cd59 100644 --- a/rpcs3/Emu/RSX/RSXFIFO.h +++ b/rpcs3/Emu/RSX/RSXFIFO.h @@ -2,23 +2,10 @@ #include #include -#include -#include #include "rsx_utils.h" #include "Emu/Cell/lv2/sys_rsx.h" -#include -#include -#include -#include - -#ifndef __unused -#define __unused(expression) do { (void)(expression); } while(0) -#endif - -struct RsxDmaControl; - namespace rsx { class thread; @@ -72,7 +59,33 @@ namespace rsx application_not_compatible }; - std::array m_register_properties; + // Workaround for MSVC, C2248 + static constexpr u8 register_props_always_ignore = register_props::always_ignore; + + static constexpr std::array m_register_properties = [] + { + constexpr std::array, 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 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; @@ -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; } From 879160bd401d9c6b38ca5d7333c68add0ccadd53 Mon Sep 17 00:00:00 2001 From: scribam Date: Mon, 3 Jun 2019 08:04:51 +0200 Subject: [PATCH 2/3] utilities: Add constexpr to color4_base For consistency with the others colorX_base --- Utilities/geometry.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Utilities/geometry.h b/Utilities/geometry.h index 8ffc05e16896..6435afaa143e 100644 --- a/Utilities/geometry.h +++ b/Utilities/geometry.h @@ -841,7 +841,7 @@ struct color4_base T xyzw[4]; }; - color4_base() + constexpr color4_base() : x{} , y{} , z{} @@ -849,7 +849,7 @@ struct color4_base { } - 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) @@ -857,18 +857,18 @@ struct color4_base { } - 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 - operator color4_base() const + constexpr operator color4_base() const { return{ (NT)x, (NT)y, (NT)z, (NT)w }; } From b2b4300264a78a70db8daf58607ad82d09aff74c Mon Sep 17 00:00:00 2001 From: scribam Date: Sun, 9 Jun 2019 09:03:27 +0200 Subject: [PATCH 3/3] gl/vk: Add constexpr to varying_registers and sync functions between the two backends --- rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp | 55 +++++++++++++------------ rpcs3/Emu/RSX/GL/GLCommonDecompiler.h | 6 +-- rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp | 2 +- rpcs3/Emu/RSX/GL/GLVertexProgram.cpp | 1 + rpcs3/Emu/RSX/VK/VKCommonDecompiler.cpp | 18 ++++---- rpcs3/Emu/RSX/VK/VKCommonDecompiler.h | 9 +--- rpcs3/Emu/RSX/VK/VKCompute.h | 1 + rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp | 10 ++--- rpcs3/Emu/RSX/VK/VKVertexProgram.cpp | 10 ++--- 9 files changed, 51 insertions(+), 61 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp b/rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp index 0e3823e02861..bb67c0249a77 100644 --- a/rpcs3/Emu/RSX/GL/GLCommonDecompiler.cpp +++ b/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 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, 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); } } diff --git a/rpcs3/Emu/RSX/GL/GLCommonDecompiler.h b/rpcs3/Emu/RSX/GL/GLCommonDecompiler.h index 2632f8edc51c..b99cf5f96f4b 100644 --- a/rpcs3/Emu/RSX/GL/GLCommonDecompiler.h +++ b/rpcs3/Emu/RSX/GL/GLCommonDecompiler.h @@ -1,10 +1,6 @@ #pragma once -#include "../Common/ShaderParam.h" -#include "../Common/GLSLCommon.h" -#include - namespace gl { - int get_varying_register_location(const std::string &var_name); + int get_varying_register_location(std::string_view varying_register_name); } diff --git a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp index 9d7a473c0f78..6aa4f62f93a0 100644 --- a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp @@ -6,7 +6,7 @@ #include "GLFragmentProgram.h" #include "GLCommonDecompiler.h" #include "../GCM.h" - +#include "../Common/GLSLCommon.h" std::string GLFragmentDecompilerThread::getFloatTypeName(size_t elementCount) { diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp index 9d2cb5b076bb..e7df99d6d3ea 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp @@ -5,6 +5,7 @@ #include "GLCommonDecompiler.h" #include "GLHelpers.h" #include "../GCM.h" +#include "../Common/GLSLCommon.h" #include diff --git a/rpcs3/Emu/RSX/VK/VKCommonDecompiler.cpp b/rpcs3/Emu/RSX/VK/VKCommonDecompiler.cpp index 8c44888dae53..f13bf37ca29b 100644 --- a/rpcs3/Emu/RSX/VK/VKCommonDecompiler.cpp +++ b/rpcs3/Emu/RSX/VK/VKCommonDecompiler.cpp @@ -105,8 +105,8 @@ namespace vk rsc.limits.generalConstantMatrixVectorIndexing = 1; } - static const varying_register_t varying_regs[] = - { + static constexpr std::array, 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& spv) diff --git a/rpcs3/Emu/RSX/VK/VKCommonDecompiler.h b/rpcs3/Emu/RSX/VK/VKCommonDecompiler.h index 6cafc88755bd..e1f85cb27e3e 100644 --- a/rpcs3/Emu/RSX/VK/VKCommonDecompiler.h +++ b/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 &spv); void initialize_compiler_context(); diff --git a/rpcs3/Emu/RSX/VK/VKCompute.h b/rpcs3/Emu/RSX/VK/VKCompute.h index b1af4bc17fd2..b2e9105245ae 100644 --- a/rpcs3/Emu/RSX/VK/VKCompute.h +++ b/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 diff --git a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp index de28c8c044fa..7682193d7aa9 100644 --- a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp @@ -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 ® = 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 ® = 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 ® = 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"; } } } diff --git a/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp b/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp index f02ea1713467..e551ad8987da 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexProgram.cpp @@ -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 ® = 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 ® = 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)