id
int64
0
755k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
65
repo_stars
int64
100
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
9 values
repo_extraction_date
stringclasses
92 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
6,119
RSXFragmentProgram.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Program/RSXFragmentProgram.h
#pragma once #include "program_util.h" #include <string> #include <vector> enum register_type { RSX_FP_REGISTER_TYPE_TEMP = 0, RSX_FP_REGISTER_TYPE_INPUT = 1, RSX_FP_REGISTER_TYPE_CONSTANT = 2, RSX_FP_REGISTER_TYPE_UNKNOWN = 3, }; enum register_precision { RSX_FP_PRECISION_REAL = 0, RSX_FP_PRECISION_HALF = 1, RSX_FP_PRECISION_FIXED12 = 2, RSX_FP_PRECISION_FIXED9 = 3, RSX_FP_PRECISION_SATURATE = 4, RSX_FP_PRECISION_UNKNOWN = 5 // Unknown what this actually does; seems to do nothing on hwtests but then why would their compiler emit it? }; enum fp_opcode { RSX_FP_OPCODE_NOP = 0x00, // No-Operation RSX_FP_OPCODE_MOV = 0x01, // Move RSX_FP_OPCODE_MUL = 0x02, // Multiply RSX_FP_OPCODE_ADD = 0x03, // Add RSX_FP_OPCODE_MAD = 0x04, // Multiply-Add RSX_FP_OPCODE_DP3 = 0x05, // 3-component Dot Product RSX_FP_OPCODE_DP4 = 0x06, // 4-component Dot Product RSX_FP_OPCODE_DST = 0x07, // Distance RSX_FP_OPCODE_MIN = 0x08, // Minimum RSX_FP_OPCODE_MAX = 0x09, // Maximum RSX_FP_OPCODE_SLT = 0x0A, // Set-If-LessThan RSX_FP_OPCODE_SGE = 0x0B, // Set-If-GreaterEqual RSX_FP_OPCODE_SLE = 0x0C, // Set-If-LessEqual RSX_FP_OPCODE_SGT = 0x0D, // Set-If-GreaterThan RSX_FP_OPCODE_SNE = 0x0E, // Set-If-NotEqual RSX_FP_OPCODE_SEQ = 0x0F, // Set-If-Equal RSX_FP_OPCODE_FRC = 0x10, // Fraction (fract) RSX_FP_OPCODE_FLR = 0x11, // Floor RSX_FP_OPCODE_KIL = 0x12, // Kill fragment RSX_FP_OPCODE_PK4 = 0x13, // Pack four signed 8-bit values RSX_FP_OPCODE_UP4 = 0x14, // Unpack four signed 8-bit values RSX_FP_OPCODE_DDX = 0x15, // Partial-derivative in x (Screen space derivative w.r.t. x) RSX_FP_OPCODE_DDY = 0x16, // Partial-derivative in y (Screen space derivative w.r.t. y) RSX_FP_OPCODE_TEX = 0x17, // Texture lookup RSX_FP_OPCODE_TXP = 0x18, // Texture sample with projection (Projective texture lookup) RSX_FP_OPCODE_TXD = 0x19, // Texture sample with partial differentiation (Texture lookup with derivatives) RSX_FP_OPCODE_RCP = 0x1A, // Reciprocal RSX_FP_OPCODE_RSQ = 0x1B, // Reciprocal Square Root RSX_FP_OPCODE_EX2 = 0x1C, // Exponentiation base 2 RSX_FP_OPCODE_LG2 = 0x1D, // Log base 2 RSX_FP_OPCODE_LIT = 0x1E, // Lighting coefficients RSX_FP_OPCODE_LRP = 0x1F, // Linear Interpolation RSX_FP_OPCODE_STR = 0x20, // Set-If-True RSX_FP_OPCODE_SFL = 0x21, // Set-If-False RSX_FP_OPCODE_COS = 0x22, // Cosine RSX_FP_OPCODE_SIN = 0x23, // Sine RSX_FP_OPCODE_PK2 = 0x24, // Pack two 16-bit floats RSX_FP_OPCODE_UP2 = 0x25, // Unpack two 16-bit floats RSX_FP_OPCODE_POW = 0x26, // Power RSX_FP_OPCODE_PKB = 0x27, // Pack bytes RSX_FP_OPCODE_UPB = 0x28, // Unpack bytes RSX_FP_OPCODE_PK16 = 0x29, // Pack 16 bits RSX_FP_OPCODE_UP16 = 0x2A, // Unpack 16 RSX_FP_OPCODE_BEM = 0x2B, // Bump-environment map (a.k.a. 2D coordinate transform) RSX_FP_OPCODE_PKG = 0x2C, // Pack with sRGB transformation RSX_FP_OPCODE_UPG = 0x2D, // Unpack gamma RSX_FP_OPCODE_DP2A = 0x2E, // 2-component dot product with scalar addition RSX_FP_OPCODE_TXL = 0x2F, // Texture sample with explicit LOD RSX_FP_OPCODE_TXB = 0x31, // Texture sample with bias RSX_FP_OPCODE_TEXBEM = 0x33, RSX_FP_OPCODE_TXPBEM = 0x34, RSX_FP_OPCODE_BEMLUM = 0x35, RSX_FP_OPCODE_REFL = 0x36, // Reflection vector RSX_FP_OPCODE_TIMESWTEX = 0x37, RSX_FP_OPCODE_DP2 = 0x38, // 2-component dot product RSX_FP_OPCODE_NRM = 0x39, // Normalize RSX_FP_OPCODE_DIV = 0x3A, // Division RSX_FP_OPCODE_DIVSQ = 0x3B, // Divide by Square Root RSX_FP_OPCODE_LIF = 0x3C, // Final part of LIT RSX_FP_OPCODE_FENCT = 0x3D, // Fence T? RSX_FP_OPCODE_FENCB = 0x3E, // Fence B? RSX_FP_OPCODE_BRK = 0x40, // Break RSX_FP_OPCODE_CAL = 0x41, // Subroutine call RSX_FP_OPCODE_IFE = 0x42, // If RSX_FP_OPCODE_LOOP = 0x43, // Loop RSX_FP_OPCODE_REP = 0x44, // Repeat RSX_FP_OPCODE_RET = 0x45 // Return }; union OPDEST { u32 HEX; struct { u32 end : 1; // Set to 1 if this is the last instruction u32 dest_reg : 6; // Destination register index u32 fp16 : 1; // Destination is a half register (H0 to H47) u32 set_cond : 1; // Condition Code Registers (CC0 and CC1) are updated u32 mask_x : 1; u32 mask_y : 1; u32 mask_z : 1; u32 mask_w : 1; u32 src_attr_reg_num : 4; u32 tex_num : 4; u32 exp_tex : 1; // _bx2 u32 prec : 2; u32 opcode : 6; u32 no_dest : 1; u32 saturate : 1; // _sat }; }; union SRC0 { u32 HEX; struct { u32 reg_type : 2; u32 tmp_reg_index : 6; u32 fp16 : 1; u32 swizzle_x : 2; u32 swizzle_y : 2; u32 swizzle_z : 2; u32 swizzle_w : 2; u32 neg : 1; u32 exec_if_lt : 1; u32 exec_if_eq : 1; u32 exec_if_gr : 1; u32 cond_swizzle_x : 2; u32 cond_swizzle_y : 2; u32 cond_swizzle_z : 2; u32 cond_swizzle_w : 2; u32 abs : 1; u32 cond_mod_reg_index : 1; u32 cond_reg_index : 1; }; }; union SRC1 { u32 HEX; struct { u32 reg_type : 2; u32 tmp_reg_index : 6; u32 fp16 : 1; u32 swizzle_x : 2; u32 swizzle_y : 2; u32 swizzle_z : 2; u32 swizzle_w : 2; u32 neg : 1; u32 abs : 1; u32 src0_prec_mod : 3; // Precision modifier for src0 (many games) u32 src1_prec_mod : 3; // Precision modifier for src1 (CoD:MW series) u32 src2_prec_mod : 3; // Precision modifier for src2 (unproven, should affect MAD instruction) u32 scale : 3; u32 opcode_is_branch : 1; }; struct { u32 else_offset : 31; u32 : 1; }; // LOOP, REP struct { u32 : 2; u32 end_counter : 8; // End counter value for LOOP or rep count for REP u32 init_counter : 8; // Initial counter value for LOOP u32 : 1; u32 increment : 8; // Increment value for LOOP }; }; union SRC2 { u32 HEX; u32 end_offset; struct { u32 reg_type : 2; u32 tmp_reg_index : 6; u32 fp16 : 1; u32 swizzle_x : 2; u32 swizzle_y : 2; u32 swizzle_z : 2; u32 swizzle_w : 2; u32 neg : 1; u32 abs : 1; u32 addr_reg : 11; u32 use_index_reg : 1; u32 perspective_corr : 1; }; }; constexpr const char* rsx_fp_input_attr_regs[] = { "WPOS", "COL0", "COL1", "FOGC", "TEX0", "TEX1", "TEX2", "TEX3", "TEX4", "TEX5", "TEX6", "TEX7", "TEX8", "TEX9", "SSA" }; static const std::string rsx_fp_op_names[] = { "NOP", "MOV", "MUL", "ADD", "MAD", "DP3", "DP4", "DST", "MIN", "MAX", "SLT", "SGE", "SLE", "SGT", "SNE", "SEQ", "FRC", "FLR", "KIL", "PK4", "UP4", "DDX", "DDY", "TEX", "TXP", "TXD", "RCP", "RSQ", "EX2", "LG2", "LIT", "LRP", "STR", "SFL", "COS", "SIN", "PK2", "UP2", "POW", "PKB", "UPB", "PK16", "UP16", "BEM", "PKG", "UPG", "DP2A", "TXL", "NULL", "TXB", "NULL", "TEXBEM", "TXPBEM", "BEMLUM", "REFL", "TIMESWTEX", "DP2", "NRM", "DIV", "DIVSQ", "LIF", "FENCT", "FENCB", "NULL", "BRK", "CAL", "IFE", "LOOP", "REP", "RET" }; struct RSXFragmentProgram { struct data_storage_helper { void* data_ptr = nullptr; std::vector<char> local_storage{}; data_storage_helper() = default; data_storage_helper(void* ptr) { data_ptr = ptr; local_storage.clear(); } data_storage_helper(const data_storage_helper& other) { this->operator=(other); } data_storage_helper(data_storage_helper&& other) noexcept : data_ptr(other.data_ptr) , local_storage(std::move(other.local_storage)) { other.data_ptr = nullptr; } data_storage_helper& operator=(const data_storage_helper& other) { if (this == &other) return *this; if (other.data_ptr == other.local_storage.data()) { local_storage = other.local_storage; data_ptr = local_storage.data(); } else { data_ptr = other.data_ptr; local_storage.clear(); } return *this; } data_storage_helper& operator=(data_storage_helper&& other) noexcept { if (this == &other) return *this; data_ptr = other.data_ptr; local_storage = std::move(other.local_storage); other.data_ptr = nullptr; return *this; } void deep_copy(u32 max_length) { if (local_storage.empty() && data_ptr) { local_storage.resize(max_length); std::memcpy(local_storage.data(), data_ptr, max_length); data_ptr = local_storage.data(); } } } mutable data{}; u32 offset = 0; u32 ucode_length = 0; u32 total_length = 0; u32 ctrl = 0; bool two_sided_lighting = false; u32 texcoord_control_mask = 0; rsx::fragment_program_texture_state texture_state; rsx::fragment_program_texture_config texture_params; bool valid = false; RSXFragmentProgram() = default; rsx::texture_dimension_extended get_texture_dimension(u8 id) const { return rsx::texture_dimension_extended{static_cast<u8>((texture_state.texture_dimensions >> (id * 2)) & 0x3)}; } bool texcoord_is_2d(u8 index) const { return !!(texcoord_control_mask & (1u << index)); } bool texcoord_is_point_coord(u8 index) const { index += 16; return !!(texcoord_control_mask & (1u << index)); } static RSXFragmentProgram clone(const RSXFragmentProgram& prog) { RSXFragmentProgram result = prog; result.clone_data(); return result; } void* get_data() const { return data.data_ptr; } void clone_data() const { ensure(ucode_length); data.deep_copy(ucode_length); } };
9,899
C++
.h
305
29.901639
139
0.605464
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,120
ShaderParam.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Program/ShaderParam.h
#pragma once #include <string> #include <vector> #include "Utilities/StrUtil.h" #include "util/types.hpp" #include <unordered_map> enum class FUNCTION { NOP, DP2, DP2A, DP3, DP4, DPH, SFL, // Set zero STR, // Set One FRACT, DFDX, DFDY, REFL, // Samplers. Must be clustered in order 1D-2D-3D; CUBE maps as a 3D texture here TEXTURE_SAMPLE_BASE, TEXTURE_SAMPLE_BIAS_BASE, TEXTURE_SAMPLE_PROJ_BASE, TEXTURE_SAMPLE_LOD_BASE, TEXTURE_SAMPLE_GRAD_BASE, TEXTURE_SAMPLE_SHADOW_BASE, TEXTURE_SAMPLE_SHADOW_PROJ_BASE, TEXTURE_SAMPLE_DEPTH_RGBA_BASE, TEXTURE_SAMPLE_DEPTH_RGBA_PROJ_BASE, TEXTURE_SAMPLE1D, TEXTURE_SAMPLE1D_BIAS, TEXTURE_SAMPLE1D_PROJ, TEXTURE_SAMPLE1D_LOD, TEXTURE_SAMPLE1D_GRAD, TEXTURE_SAMPLE1D_SHADOW, TEXTURE_SAMPLE1D_SHADOW_PROJ, TEXTURE_SAMPLE1D_DEPTH_RGBA, TEXTURE_SAMPLE1D_DEPTH_RGBA_PROJ, TEXTURE_SAMPLE2D, TEXTURE_SAMPLE2D_BIAS, TEXTURE_SAMPLE2D_PROJ, TEXTURE_SAMPLE2D_LOD, TEXTURE_SAMPLE2D_GRAD, TEXTURE_SAMPLE2D_SHADOW, TEXTURE_SAMPLE2D_SHADOW_PROJ, TEXTURE_SAMPLE2D_DEPTH_RGBA, TEXTURE_SAMPLE2D_DEPTH_RGBA_PROJ, TEXTURE_SAMPLE3D, TEXTURE_SAMPLE3D_BIAS, TEXTURE_SAMPLE3D_PROJ, TEXTURE_SAMPLE3D_LOD, TEXTURE_SAMPLE3D_GRAD, TEXTURE_SAMPLE3D_SHADOW, TEXTURE_SAMPLE3D_SHADOW_PROJ, TEXTURE_SAMPLE3D_DEPTH_RGBA, TEXTURE_SAMPLE3D_DEPTH_RGBA_PROJ, TEXTURE_SAMPLE2DMS, TEXTURE_SAMPLE2DMS_BIAS, TEXTURE_SAMPLE2DMS_PROJ, TEXTURE_SAMPLE2DMS_LOD, TEXTURE_SAMPLE2DMS_GRAD, TEXTURE_SAMPLE2DMS_SHADOW, TEXTURE_SAMPLE2DMS_SHADOW_PROJ, TEXTURE_SAMPLE2DMS_DEPTH_RGBA, TEXTURE_SAMPLE2DMS_DEPTH_RGBA_PROJ, VERTEX_TEXTURE_FETCH1D, VERTEX_TEXTURE_FETCH2D, VERTEX_TEXTURE_FETCH3D, VERTEX_TEXTURE_FETCHCUBE, VERTEX_TEXTURE_FETCH2DMS, // Meta TEXTURE_SAMPLE_MAX_BASE_ENUM = TEXTURE_SAMPLE_DEPTH_RGBA_PROJ_BASE, // Update if more base enums are added TEXTURE_SAMPLE_BASE_ENUM_COUNT = (TEXTURE_SAMPLE_MAX_BASE_ENUM - TEXTURE_SAMPLE_BASE + 1), }; enum class COMPARE { SEQ, SGE, SGT, SLE, SLT, SNE, }; enum ParamFlag { PF_PARAM_IN, PF_PARAM_OUT, PF_PARAM_UNIFORM, PF_PARAM_CONST, PF_PARAM_NONE, PF_PARAM_COUNT, }; struct ParamItem { const std::string name; const std::string value; int location; ParamItem(std::string _name, int _location, std::string _value = "") : name(std::move(_name)) , value(std::move(_value)), location(_location) { } }; struct ParamType { const ParamFlag flag; const std::string type; std::vector<ParamItem> items; ParamType(const ParamFlag _flag, std::string _type) : flag(_flag) , type(std::move(_type)) { } bool HasItem(const std::string& name) const { return std::any_of(items.cbegin(), items.cend(), [&name](const auto& item) { return item.name == name; }); } bool ReplaceOrInsert(const std::string& name, const ParamItem& item) { if (HasItem(name)) { std::vector<ParamItem> new_list; for (const auto& it : items) { if (it.name != name) { new_list.emplace_back(it.name, it.location, it.value); } else { new_list.emplace_back(item.name, item.location, item.value); } } std::swap(items, new_list); return true; } items.push_back(item); return false; } }; struct ParamArray { std::vector<ParamType> params[PF_PARAM_COUNT]; ParamType* SearchParam(const ParamFlag &flag, const std::string& type) { for (auto& param : params[flag]) { if (param.type == type) return &param; } return nullptr; } bool HasParamTypeless(const ParamFlag flag, const std::string& name) const { const auto& p = params[flag]; return std::any_of(p.cbegin(), p.cend(), [&name](const auto& param) { return param.HasItem(name); }); } bool HasParam(const ParamFlag flag, const std::string& type, const std::string& name) { ParamType* t = SearchParam(flag, type); return t && t->HasItem(name); } std::string AddParam(const ParamFlag flag, const std::string& type, const std::string& name, const std::string& value) { ParamType* t = SearchParam(flag, type); if (t) { if (!t->HasItem(name)) t->items.emplace_back(name, -1, value); } else { params[flag].emplace_back(flag, type); params[flag].back().items.emplace_back(name, -1, value); } return name; } std::string AddParam(const ParamFlag flag, const std::string& type, const std::string& name, int location = -1) { ParamType* t = SearchParam(flag, type); if (t) { if (!t->HasItem(name)) t->items.emplace_back(name, location); } else { params[flag].emplace_back(flag, type); params[flag].back().items.emplace_back(name, location); } return name; } }; class ShaderVariable { public: std::string name; std::vector<std::string> swizzles; ShaderVariable() = default; ShaderVariable(const std::string& var) { // Separate 'double destination' variables 'X=Y=SRC' std::string simple_var; const auto eq_pos = var.find('='); if (eq_pos != umax) { simple_var = var.substr(0, eq_pos - 1); } else { simple_var = var; } const auto brace_pos = var.find_last_of(')'); std::string prefix; if (brace_pos != umax) { prefix = simple_var.substr(0, brace_pos); simple_var = simple_var.substr(brace_pos); } auto var_blocks = fmt::split(simple_var, { "." }); ensure((!var_blocks.empty())); name = prefix + var_blocks[0]; if (var_blocks.size() == 1) { swizzles.emplace_back("xyzw"); } else { swizzles = std::vector<std::string>(var_blocks.begin() + 1, var_blocks.end()); } } usz get_vector_size() const { return swizzles[swizzles.size() - 1].length(); } ShaderVariable& simplify() { std::unordered_map<char, char> swizzle; static std::unordered_map<uint, char> pos_to_swizzle = { { 0, 'x' }, { 1, 'y' }, { 2, 'z' }, { 3, 'w' } }; for (auto& p : pos_to_swizzle) { swizzle[p.second] = swizzles[0].length() > p.first ? swizzles[0][p.first] : 0; } for (uint i = 1; i < swizzles.size(); ++i) { std::unordered_map<char, char> new_swizzle; for (auto& p : pos_to_swizzle) { new_swizzle[p.second] = swizzle[swizzles[i].length() <= p.first ? '\0' : swizzles[i][p.first]]; } swizzle = new_swizzle; } swizzles.clear(); std::string new_swizzle; for (auto& p : pos_to_swizzle) { if (swizzle[p.second] != '\0') new_swizzle += swizzle[p.second]; } swizzles.push_back(new_swizzle); return *this; } std::string get() const { if (swizzles.size() == 1 && swizzles[0] == "xyzw") { return name; } return name + "." + fmt::merge({ swizzles }, "."); } std::string match_size(const std::string& other_var) const { // Make other_var the same vector length as this var ShaderVariable other(other_var); const auto this_size = get_vector_size(); const auto other_size = other.get_vector_size(); if (this_size == other_size) [[likely]] { return other_var; } if (this_size < other_size) [[likely]] { switch (this_size) { case 0: case 4: return other_var; case 1: return other_var + ".x"; case 2: return other_var + ".xy"; case 3: return other_var + ".xyz"; default: fmt::throw_exception("Unreachable"); } } else { auto remaining = this_size - other_size; std::string result = other_var; while (remaining--) result += "x"; return result; } } std::string add_mask(const std::string& other_var) const { if (swizzles.back() != "xyzw") { return other_var + "." + swizzles.back(); } return other_var; } }; struct vertex_reg_info { enum mask_test_type : u8 { any = 0, // Any bit set none = 1, // No bits set all = 2, // All bits set xall = 3 // Some bits set }; std::string name; // output name bool need_declare; // needs explicit declaration as output (not language in-built) std::string src_reg; // reg to get data from std::string src_reg_mask; // input swizzle mask bool need_cast; // needs casting std::string cond; // update on condition std::string default_val; // fallback value on cond fail std::string dst_alias; // output name override bool check_mask; // check program output control mask for this output u32 check_mask_value; // program output control mask for testing mask_test_type check_flags; // whole mask must match bool test(u32 mask) const { if (!check_mask) return true; const u32 val = (mask & check_mask_value); switch (check_flags) { case none: return (val == 0); case any: return (val != 0); case all: return (val == check_mask_value); case xall: return (val && val != check_mask_value); default: fmt::throw_exception("Unreachable"); } } bool declare(u32 mask) const { return test(mask); } };
8,746
C++
.h
369
20.867209
119
0.679018
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,121
GLSLCommon.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Program/GLSLCommon.h
#pragma once #include <sstream> #include <string_view> #include "GLSLTypes.h" #include "ShaderParam.h" struct RSXFragmentProgram; namespace rsx { // TODO: Move this somewhere else once more compilers are supported other than glsl enum texture_control_bits { GAMMA_A = 0, GAMMA_R, GAMMA_G, GAMMA_B, ALPHAKILL, RENORMALIZE, EXPAND_A, EXPAND_R, EXPAND_G, EXPAND_B, SEXT_A, SEXT_R, SEXT_G, SEXT_B, DEPTH_FLOAT, DEPTH_COMPARE_OP, DEPTH_COMPARE_1, DEPTH_COMPARE_2, FILTERED_MAG, FILTERED_MIN, UNNORMALIZED_COORDS, CLAMP_TEXCOORDS_BIT, WRAP_S, WRAP_T, WRAP_R, GAMMA_CTRL_MASK = (1 << GAMMA_R) | (1 << GAMMA_G) | (1 << GAMMA_B) | (1 << GAMMA_A), EXPAND_MASK = (1 << EXPAND_R) | (1 << EXPAND_G) | (1 << EXPAND_B) | (1 << EXPAND_A), EXPAND_OFFSET = EXPAND_A, SEXT_MASK = (1 << SEXT_R) | (1 << SEXT_G) | (1 << SEXT_B) | (1 << SEXT_A), SEXT_OFFSET = SEXT_A }; enum ROP_control_bits : u32 { // Commands. These trigger explicit action. ALPHA_TEST_ENABLE_BIT = 0, SRGB_FRAMEBUFFER_BIT = 1, ALPHA_TO_COVERAGE_ENABLE_BIT = 2, POLYGON_STIPPLE_ENABLE_BIT = 3, // Auxilliary config INT_FRAMEBUFFER_BIT = 16, MSAA_WRITE_ENABLE_BIT = 17, // Data ALPHA_FUNC_OFFSET = 18, MSAA_SAMPLE_CTRL_OFFSET = 21, // Data lengths ALPHA_FUNC_NUM_BITS = 3, MSAA_SAMPLE_CTRL_NUM_BITS = 2, // Meta ROP_CMD_MASK = 0xF // Commands are encoded in the lower 16 bits }; struct ROP_control_t { u32 value = 0; void enable_alpha_test() { value |= (1u << ROP_control_bits::ALPHA_TEST_ENABLE_BIT); } void enable_framebuffer_sRGB() { value |= (1u << ROP_control_bits::SRGB_FRAMEBUFFER_BIT); } void enable_alpha_to_coverage() { value |= (1u << ROP_control_bits::ALPHA_TO_COVERAGE_ENABLE_BIT); } void enable_polygon_stipple() { value |= (1u << ROP_control_bits::POLYGON_STIPPLE_ENABLE_BIT); } void enable_framebuffer_INT() { value |= (1u << ROP_control_bits::INT_FRAMEBUFFER_BIT); } void enable_MSAA_writes() { value |= (1u << ROP_control_bits::MSAA_WRITE_ENABLE_BIT); } void set_alpha_test_func(uint func) { value |= (func << ROP_control_bits::ALPHA_FUNC_OFFSET); } void set_msaa_control(uint ctrl) { value |= (ctrl << ROP_control_bits::MSAA_SAMPLE_CTRL_OFFSET); } }; } namespace glsl { struct two_sided_lighting_config { bool two_sided_color; bool two_sided_specular; }; struct extension_flavour { static constexpr std::string_view EXT = "EXT", KHR = "KHR", NV = "NV"; }; std::string getFloatTypeNameImpl(usz elementCount); std::string getHalfTypeNameImpl(usz elementCount); std::string compareFunctionImpl(COMPARE f, const std::string &Op0, const std::string &Op1, bool scalar = false); void insert_vertex_input_fetch(std::stringstream& OS, glsl_rules rules, bool glsl4_compliant=true); void insert_rop_init(std::ostream& OS); void insert_rop(std::ostream& OS, const shader_properties& props); void insert_glsl_legacy_function(std::ostream& OS, const shader_properties& props); std::string getFunctionImpl(FUNCTION f); void insert_subheader_block(std::ostream& OS); void insert_fragment_shader_inputs_block( std::stringstream& OS, const std::string_view bary_coords_extenstion_type, const RSXFragmentProgram& prog, const std::vector<ParamType>& params, const two_sided_lighting_config& _2sided_lighting, std::function<int(std::string_view)> varying_location); }
3,469
C++
.h
105
30.32381
113
0.684792
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,122
GLSLTypes.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Program/GLSLTypes.h
#pragma once namespace glsl { enum program_domain : unsigned char { glsl_vertex_program = 0, glsl_fragment_program = 1, glsl_compute_program = 2 }; enum glsl_rules : unsigned char { glsl_rules_opengl4, glsl_rules_vulkan }; struct shader_properties { glsl::program_domain domain : 3; // Applicable in vertex stage bool require_lit_emulation : 1; bool require_explicit_invariance : 1; bool emulate_zclip_transform : 1; bool emulate_depth_clip_only : 1; // Only relevant for fragment programs bool fp32_outputs : 1; bool require_wpos : 1; bool require_srgb_to_linear : 1; bool require_linear_to_srgb : 1; bool require_fog_read : 1; bool emulate_coverage_tests : 1; bool emulate_shadow_compare : 1; bool low_precision_tests : 1; bool disable_early_discard : 1; bool supports_native_fp16 : 1; bool ROP_output_rounding : 1; // Texturing spec bool require_texture_ops : 1; // Global switch to enable/disable all texture code bool require_depth_conversion : 1; // Include DSV<->RTV bitcast emulation bool require_tex_shadow_ops : 1; // Include shadow compare emulation bool require_msaa_ops : 1; // Include MSAA<->Resolved bitcast emulation bool require_texture_expand : 1; // Include sign-expansion emulation bool require_tex1D_ops : 1; // Include 1D texture stuff bool require_tex2D_ops : 1; // Include 2D texture stuff bool require_tex3D_ops : 1; // Include 3D texture stuff (including cubemap) bool require_shadowProj_ops : 1; // Include shadow2DProj projection textures (1D is unsupported anyway) }; };
1,666
C++
.h
46
33.456522
112
0.697026
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,123
ProgramStateCache.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Program/ProgramStateCache.h
#pragma once #include "RSXFragmentProgram.h" #include "RSXVertexProgram.h" #include "Utilities/mutex.h" #include "util/logs.hpp" #include "util/fnv_hash.hpp" #include <span> #include <unordered_map> enum class SHADER_TYPE { SHADER_TYPE_VERTEX, SHADER_TYPE_FRAGMENT }; namespace program_hash_util { struct vertex_program_utils { struct vertex_program_metadata { std::bitset<rsx::max_vertex_program_instructions> instruction_mask; u32 ucode_length; u32 referenced_textures_mask; u16 referenced_inputs_mask; u16 reserved; }; static usz get_vertex_program_ucode_hash(const RSXVertexProgram &program); static vertex_program_metadata analyse_vertex_program(const u32* data, u32 entry, RSXVertexProgram& dst_prog); }; struct vertex_program_storage_hash { usz operator()(const RSXVertexProgram &program) const; }; struct vertex_program_compare { bool operator()(const RSXVertexProgram &binary1, const RSXVertexProgram &binary2) const; }; struct fragment_program_utils { struct fragment_program_metadata { u32 program_start_offset; u32 program_ucode_length; u32 program_constants_buffer_length; u16 referenced_textures_mask; bool has_pack_instructions; bool has_branch_instructions; bool is_nop_shader; // Does this affect Z-pass testing??? }; /** * returns true if the given source Operand is a constant */ static bool is_constant(u32 sourceOperand); static usz get_fragment_program_ucode_size(const void* ptr); static fragment_program_metadata analyse_fragment_program(const void* ptr); static usz get_fragment_program_ucode_hash(const RSXFragmentProgram &program); }; struct fragment_program_storage_hash { usz operator()(const RSXFragmentProgram &program) const; }; struct fragment_program_compare { bool operator()(const RSXFragmentProgram &binary1, const RSXFragmentProgram &binary2) const; }; } namespace rsx { void write_fragment_constants_to_buffer(const std::span<f32>& buffer, const RSXFragmentProgram& rsx_prog, const std::vector<usz>& offsets_cache, bool sanitize = true); } /** * Cache for program help structure (blob, string...) * The class is responsible for creating the object so the state only has to call getGraphicPipelineState * Template argument is a struct which has the following type declaration : * - a typedef VertexProgramData to a type that encapsulate vertex program info. It should provide an Id member. * - a typedef FragmentProgramData to a types that encapsulate fragment program info. It should provide an Id member and a fragment constant offset vector. * - a typedef PipelineData encapsulating monolithic program. * - a typedef PipelineProperties to a type that encapsulate various state info relevant to program compilation (alpha test, primitive type,...) * - a typedef ExtraData type that will be passed to the buildProgram function. * It should also contains the following function member : * - static void recompile_fragment_program(RSXFragmentProgram *RSXFP, FragmentProgramData& fragmentProgramData, usz ID); * - static void recompile_vertex_program(RSXVertexProgram *RSXVP, VertexProgramData& vertexProgramData, usz ID); * - static PipelineData build_program(VertexProgramData &vertexProgramData, FragmentProgramData &fragmentProgramData, const PipelineProperties &pipelineProperties, const ExtraData& extraData); * - static void validate_pipeline_properties(const VertexProgramData &vertexProgramData, const FragmentProgramData &fragmentProgramData, PipelineProperties& props); */ template<typename backend_traits> class program_state_cache { using pipeline_storage_type = typename backend_traits::pipeline_storage_type; using pipeline_type = typename backend_traits::pipeline_type; using pipeline_properties = typename backend_traits::pipeline_properties; using vertex_program_type = typename backend_traits::vertex_program_type; using fragment_program_type = typename backend_traits::fragment_program_type; using binary_to_vertex_program = std::unordered_map<RSXVertexProgram, vertex_program_type, program_hash_util::vertex_program_storage_hash, program_hash_util::vertex_program_compare> ; using binary_to_fragment_program = std::unordered_map<RSXFragmentProgram, fragment_program_type, program_hash_util::fragment_program_storage_hash, program_hash_util::fragment_program_compare>; using pipeline_data_type = std::tuple<pipeline_type*, const vertex_program_type*, const fragment_program_type*>; struct pipeline_key { u32 vertex_program_id; u32 fragment_program_id; pipeline_properties properties; }; struct pipeline_key_hash { usz operator()(const pipeline_key &key) const { usz hashValue = 0; hashValue ^= rpcs3::hash_base<unsigned>(key.vertex_program_id); hashValue ^= rpcs3::hash_base<unsigned>(key.fragment_program_id); hashValue ^= rpcs3::hash_struct<pipeline_properties>(key.properties); return hashValue; } }; struct pipeline_key_compare { bool operator()(const pipeline_key &key1, const pipeline_key &key2) const { return (key1.vertex_program_id == key2.vertex_program_id) && (key1.fragment_program_id == key2.fragment_program_id) && (key1.properties == key2.properties); } }; protected: using decompiler_callback_t = std::function<void(const pipeline_properties&, const RSXVertexProgram&, const RSXFragmentProgram&)>; shared_mutex m_vertex_mutex; shared_mutex m_fragment_mutex; shared_mutex m_pipeline_mutex; shared_mutex m_decompiler_mutex; atomic_t<usz> m_next_id = 0; bool m_cache_miss_flag; // Set if last lookup did not find any usable cached programs binary_to_vertex_program m_vertex_shader_cache; binary_to_fragment_program m_fragment_shader_cache; std::unordered_map<pipeline_key, pipeline_storage_type, pipeline_key_hash, pipeline_key_compare> m_storage; decompiler_callback_t notify_pipeline_compiled; vertex_program_type __null_vertex_program; fragment_program_type __null_fragment_program; pipeline_storage_type __null_pipeline_handle; /// bool here to inform that the program was preexisting. std::tuple<const vertex_program_type&, bool> search_vertex_program(const RSXVertexProgram& rsx_vp, bool force_load = true) { bool recompile = false; vertex_program_type* new_shader; { reader_lock lock(m_vertex_mutex); const auto& I = m_vertex_shader_cache.find(rsx_vp); if (I != m_vertex_shader_cache.end()) { return std::forward_as_tuple(I->second, true); } if (!force_load) { return std::forward_as_tuple(__null_vertex_program, false); } rsx_log.trace("VP not found in buffer!"); lock.upgrade(); auto [it, inserted] = m_vertex_shader_cache.try_emplace(rsx_vp); new_shader = &(it->second); recompile = inserted; } if (recompile) { backend_traits::recompile_vertex_program(rsx_vp, *new_shader, m_next_id++); } return std::forward_as_tuple(*new_shader, false); } /// bool here to inform that the program was preexisting. std::tuple<const fragment_program_type&, bool> search_fragment_program(const RSXFragmentProgram& rsx_fp, bool force_load = true) { bool recompile = false; typename binary_to_fragment_program::iterator it; fragment_program_type* new_shader; { reader_lock lock(m_fragment_mutex); const auto& I = m_fragment_shader_cache.find(rsx_fp); if (I != m_fragment_shader_cache.end()) { return std::forward_as_tuple(I->second, true); } if (!force_load) { return std::forward_as_tuple(__null_fragment_program, false); } rsx_log.trace("FP not found in buffer!"); lock.upgrade(); std::tie(it, recompile) = m_fragment_shader_cache.try_emplace(rsx_fp); new_shader = &(it->second); } if (recompile) { it->first.clone_data(); backend_traits::recompile_fragment_program(rsx_fp, *new_shader, m_next_id++); } return std::forward_as_tuple(*new_shader, false); } public: struct program_buffer_patch_entry { union { u32 hex_key; f32 fp_key; }; union { u32 hex_value; f32 fp_value; }; program_buffer_patch_entry() = default; program_buffer_patch_entry(f32& key, f32& value) { fp_key = key; fp_value = value; } program_buffer_patch_entry(u32& key, u32& value) { hex_key = key; hex_value = value; } bool test_and_set(f32 value, f32* dst) const { u32 hex = std::bit_cast<u32>(value); if ((hex & 0x7FFFFFFF) == (hex_key & 0x7FFFFFFF)) { hex = (hex & ~0x7FFFFFF) | hex_value; *dst = std::bit_cast<f32>(hex); return true; } return false; } }; public: program_state_cache() = default; ~program_state_cache() {} template<typename... Args> pipeline_data_type get_graphics_pipeline( const RSXVertexProgram& vertexShader, const RSXFragmentProgram& fragmentShader, pipeline_properties& pipelineProperties, bool compile_async, bool allow_notification, Args&& ...args ) { const auto &vp_search = search_vertex_program(vertexShader); const auto &fp_search = search_fragment_program(fragmentShader); const bool already_existing_fragment_program = std::get<1>(fp_search); const bool already_existing_vertex_program = std::get<1>(vp_search); const vertex_program_type& vertex_program = std::get<0>(vp_search); const fragment_program_type& fragment_program = std::get<0>(fp_search); const pipeline_key key = { vertex_program.id, fragment_program.id, pipelineProperties }; m_cache_miss_flag = true; if (already_existing_vertex_program && already_existing_fragment_program) { // There is a high chance the pipeline object was compiled if the two shaders already existed before backend_traits::validate_pipeline_properties(vertex_program, fragment_program, pipelineProperties); reader_lock lock(m_pipeline_mutex); if (const auto I = m_storage.find(key); I != m_storage.end()) { m_cache_miss_flag = (I->second == __null_pipeline_handle); return { I->second.get(), &vertex_program, &fragment_program }; } } { std::lock_guard lock(m_pipeline_mutex); // Check if another submission completed in the mean time if (const auto I = m_storage.find(key); I != m_storage.end()) { m_cache_miss_flag = (I->second == __null_pipeline_handle); return { I->second.get(), &vertex_program, &fragment_program }; } // Insert a placeholder if the key still doesn't exist to avoid re-linking of the same pipeline m_storage[key] = std::move(__null_pipeline_handle); } rsx_log.notice("Add program (vp id = %d, fp id = %d)", vertex_program.id, fragment_program.id); std::function<pipeline_type* (pipeline_storage_type&)> callback; if (allow_notification) { callback = [this, vertexShader, fragmentShader_ = RSXFragmentProgram::clone(fragmentShader), key] (pipeline_storage_type& pipeline) -> pipeline_type* { if (!pipeline) { return nullptr; } rsx_log.success("Program compiled successfully"); notify_pipeline_compiled(key.properties, vertexShader, fragmentShader_); std::lock_guard lock(m_pipeline_mutex); auto& pipe_result = m_storage[key]; pipe_result = std::move(pipeline); return pipe_result.get(); }; } else { callback = [this, key](pipeline_storage_type& pipeline) -> pipeline_type* { if (!pipeline) { return nullptr; } std::lock_guard lock(m_pipeline_mutex); auto& pipe_result = m_storage[key]; pipe_result = std::move(pipeline); return pipe_result.get(); }; } auto result = backend_traits::build_pipeline( vertex_program, // VS, must already be decompiled and recompiled above fragment_program, // FS, must already be decompiled and recompiled above pipelineProperties, // Pipeline state compile_async, // Allow asynchronous compilation callback, // Insertion and notification callback std::forward<Args>(args)...); // Other arguments return { result, &vertex_program, &fragment_program }; } void fill_fragment_constants_buffer(std::span<f32> dst_buffer, const fragment_program_type& fragment_program, const RSXFragmentProgram& rsx_prog, bool sanitize = false) const { ensure((dst_buffer.size_bytes() >= ::narrow<int>(fragment_program.FragmentConstantOffsetCache.size()) * 16u)); rsx::write_fragment_constants_to_buffer(dst_buffer, rsx_prog, fragment_program.FragmentConstantOffsetCache, sanitize); } void clear() { std::scoped_lock lock(m_vertex_mutex, m_fragment_mutex, m_decompiler_mutex, m_pipeline_mutex); notify_pipeline_compiled = {}; m_fragment_shader_cache.clear(); m_vertex_shader_cache.clear(); m_storage.clear(); } };
12,655
C++
.h
327
35.501529
193
0.736657
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,124
ShaderInterpreter.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Program/ShaderInterpreter.h
#pragma once namespace program_common { namespace interpreter { enum compiler_option { COMPILER_OPT_ENABLE_TEXTURES = 1, COMPILER_OPT_ENABLE_DEPTH_EXPORT = 2, COMPILER_OPT_ENABLE_F32_EXPORT = 4, COMPILER_OPT_ENABLE_ALPHA_TEST_GE = 8, COMPILER_OPT_ENABLE_ALPHA_TEST_G = 16, COMPILER_OPT_ENABLE_ALPHA_TEST_LE = 32, COMPILER_OPT_ENABLE_ALPHA_TEST_L = 64, COMPILER_OPT_ENABLE_ALPHA_TEST_EQ = 128, COMPILER_OPT_ENABLE_ALPHA_TEST_NE = 256, COMPILER_OPT_ENABLE_FLOW_CTRL = 512, COMPILER_OPT_ENABLE_PACKING = 1024, COMPILER_OPT_ENABLE_KIL = 2048, COMPILER_OPT_ENABLE_STIPPLING = 4096 }; static std::string get_vertex_interpreter() { const char* s = #include "../Program/GLSLInterpreter/VertexInterpreter.glsl" ; return s; } static std::string get_fragment_interpreter() { const char* s = #include "../Program/GLSLInterpreter/FragmentInterpreter.glsl" ; return s; } } }
988
C++
.h
37
22.27027
66
0.686772
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,125
OpenGL.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/OpenGL.h
#pragma once #ifndef _WIN32 #include <GL/glew.h> #endif #ifdef _WIN32 #include <Windows.h> #include "GL/gl.h" #include <glext.h> typedef BOOL (WINAPI* PFNWGLSWAPINTERVALEXTPROC) (int interval); #define OPENGL_PROC(p, n) extern p gl##n #define WGL_PROC(p, n) extern p wgl##n #define OPENGL_PROC2(p, n, tn) OPENGL_PROC(p, n) #include "GLProcTable.h" #undef OPENGL_PROC #undef WGL_PROC #undef OPENGL_PROC2 #elif defined(__APPLE__) #include <OpenGL/gl.h> #include <OpenGL/glu.h> #else #include <GL/gl.h> #ifdef HAVE_X11 #include <GL/glxew.h> #include <GL/glx.h> #include <GL/glxext.h> #endif #endif #ifndef GL_TEXTURE_BUFFER_BINDING //During spec release, this enum was removed during upgrade from ARB equivalent //See https://www.khronos.org/bugzilla/show_bug.cgi?id=844 #define GL_TEXTURE_BUFFER_BINDING 0x8C2A #endif namespace gl { void init(); void set_swapinterval(int interval); }
892
C++
.h
37
22.864865
79
0.763251
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,126
GLDMA.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLDMA.h
#pragma once #include <util/types.hpp> #include "Utilities/address_range.h" #include "glutils/buffer_object.h" // TODO: Unify the DMA implementation across backends as part of RSX restructuring. namespace gl { using dma_mapping_handle = std::pair<u32, gl::buffer*>; dma_mapping_handle map_dma(u32 guest_addr, u32 length); void clear_dma_resources(); // GL does not currently support mixed block types... class dma_block { public: dma_block() = default; void allocate(u32 base_address, u32 block_size); void resize(u32 new_length); void* map(const utils::address_range& range) const; void set_parent(const dma_block* other); const dma_block* head() const { return m_parent ? m_parent : this; } bool can_map(const utils::address_range& range) const; u32 base_addr() const { return m_base_address; } u32 length() const { return m_data ? static_cast<u32>(m_data->size()) : 0; } bool empty() const { return length() == 0; } buffer* get() const { return m_data.get(); } utils::address_range range() const { return utils::address_range::start_length(m_base_address, length()); } protected: u32 m_base_address = 0; const dma_block* m_parent = nullptr; std::unique_ptr<gl::buffer> m_data; }; }
1,274
C++
.h
32
36.03125
110
0.695261
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,127
GLFragmentProgram.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLFragmentProgram.h
#pragma once #include "../Program/FragmentProgramDecompiler.h" #include "../Program/GLSLTypes.h" #include "GLHelpers.h" #include "glutils/program.h" namespace glsl { struct shader_properties; } namespace gl { class shader_interpreter; } struct GLFragmentDecompilerThread : public FragmentProgramDecompiler { friend class gl::shader_interpreter; std::string& m_shader; ParamArray& m_parrDummy; glsl::shader_properties m_shader_props{}; public: GLFragmentDecompilerThread(std::string& shader, ParamArray& parr, const RSXFragmentProgram &prog, u32& size) : FragmentProgramDecompiler(prog, size) , m_shader(shader) , m_parrDummy(parr) { } void Task(); protected: std::string getFloatTypeName(usz elementCount) override; std::string getHalfTypeName(usz elementCount) override; std::string getFunction(FUNCTION) override; std::string compareFunction(COMPARE, const std::string&, const std::string&) override; void insertHeader(std::stringstream &OS) override; void insertInputs(std::stringstream &OS) override; void insertOutputs(std::stringstream &OS) override; void insertConstants(std::stringstream &OS) override; void insertGlobalFunctions(std::stringstream &OS) override; void insertMainStart(std::stringstream &OS) override; void insertMainEnd(std::stringstream &OS) override; }; /** Storage for an Fragment Program in the process of of recompilation. * This class calls OpenGL functions and should only be used from the RSX/Graphics thread. */ class GLFragmentProgram { public: GLFragmentProgram(); ~GLFragmentProgram(); ParamArray parr; u32 id; gl::glsl::shader shader; std::vector<usz> FragmentConstantOffsetCache; /** * Decompile a fragment shader located in the PS3's Memory. This function operates synchronously. * @param prog RSXShaderProgram specifying the location and size of the shader in memory */ void Decompile(const RSXFragmentProgram& prog); private: /** Deletes the shader and any stored information */ void Delete(); };
1,997
C++
.h
61
30.803279
109
0.794699
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,128
GLOverlays.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLOverlays.h
#pragma once #include "Emu/system_config_types.h" #include "util/types.hpp" #include "../Common/simple_array.hpp" #include "../Overlays/overlays.h" #include "GLTexture.h" #include "glutils/fbo.h" #include "glutils/program.h" #include "glutils/vao.hpp" #include <string> #include <unordered_map> namespace gl { struct overlay_pass { std::string fs_src; std::string vs_src; gl::glsl::program program_handle; gl::glsl::shader vs; gl::glsl::shader fs; gl::fbo fbo; gl::sampler_state m_sampler; gl::vao m_vao; gl::buffer m_vertex_data_buffer; bool compiled = false; u32 num_drawable_elements = 4; GLenum primitives = GL_TRIANGLE_STRIP; gl::filter m_input_filter = gl::filter::nearest; u32 m_write_aspect_mask = gl::image_aspect::color | gl::image_aspect::depth; bool enable_depth_writes = false; bool enable_stencil_writes = false; virtual ~overlay_pass() = default; void create(); void destroy(); virtual void on_load() {} virtual void on_unload() {} virtual void bind_resources() {} virtual void cleanup_resources() {} template <typename T> void upload_vertex_data(T* data, u32 elements_count) { m_vertex_data_buffer.data(elements_count * sizeof(T), data); } virtual void emit_geometry(); void run(gl::command_context& cmd, const areau& region, GLuint target_texture, GLuint image_aspect_bits, bool enable_blending = false); }; struct ui_overlay_renderer final : public overlay_pass { u32 num_elements = 0; std::vector<std::unique_ptr<gl::texture>> resources; std::unordered_map<u64, std::pair<u32, std::unique_ptr<gl::texture>>> temp_image_cache; std::unordered_map<u64, std::unique_ptr<gl::texture_view>> temp_view_cache; std::unordered_map<u64, std::unique_ptr<gl::texture>> font_cache; std::unordered_map<u64, std::unique_ptr<gl::texture_view>> view_cache; rsx::overlays::primitive_type m_current_primitive_type = rsx::overlays::primitive_type::quad_list; ui_overlay_renderer(); gl::texture_view* load_simple_image(rsx::overlays::image_info* desc, bool temp_resource, u32 owner_uid); void create(); void destroy(); void remove_temp_resources(u64 key); gl::texture_view* find_font(rsx::overlays::font* font); gl::texture_view* find_temp_image(rsx::overlays::image_info* desc, u32 owner_uid); void set_primitive_type(rsx::overlays::primitive_type type); void emit_geometry() override; void run(gl::command_context& cmd, const areau& viewport, GLuint target, rsx::overlays::overlay& ui); }; struct video_out_calibration_pass final : public overlay_pass { video_out_calibration_pass(); void run(gl::command_context& cmd, const areau& viewport, const rsx::simple_array<GLuint>& source, f32 gamma, bool limited_rgb, stereo_render_mode_options stereo_mode, gl::filter input_filter); }; struct rp_ssbo_to_generic_texture final : public overlay_pass { rp_ssbo_to_generic_texture(); void run(gl::command_context& cmd, const buffer* src, texture* dst, const u32 src_offset, const coordu& dst_region, const pixel_buffer_layout& layout); void run(gl::command_context& cmd, const buffer* src, const texture_view* dst, const u32 src_offset, const coordu& dst_region, const pixel_buffer_layout& layout); }; // TODO: Replace with a proper manager extern std::unordered_map<u32, std::unique_ptr<gl::overlay_pass>> g_overlay_passes; template<class T> T* get_overlay_pass() { u32 index = id_manager::typeinfo::get_index<T>(); auto &e = g_overlay_passes[index]; if (!e) { e = std::make_unique<T>(); e->create(); } return static_cast<T*>(e.get()); } void destroy_overlay_passes(); }
3,639
C++
.h
93
36.225806
195
0.724295
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,129
GLHelpers.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLHelpers.h
#pragma once #include <string> #include <functional> #include <vector> #include <memory> #include <unordered_map> #include <algorithm> #include "../GCM.h" #include "../Common/TextureUtils.h" #include "../Program/GLSLTypes.h" #include "Utilities/mutex.h" #include "Utilities/geometry.h" #include "Utilities/File.h" #include "util/logs.hpp" #include "util/asm.hpp" #include "glutils/common.h" // TODO: Include on use #include "glutils/buffer_object.h" #include "glutils/image.h" #include "glutils/sampler.h" #include "glutils/pixel_settings.hpp" #include "glutils/state_tracker.hpp" // Noop keyword outside of Windows (used in log_debug) #if !defined(_WIN32) && !defined(APIENTRY) #define APIENTRY #endif namespace gl { void enable_debugging(); bool is_primitive_native(rsx::primitive_type in); GLenum draw_mode(rsx::primitive_type in); }
847
C++
.h
32
25.15625
54
0.767327
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,130
GLTextureCache.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLTextureCache.h
#pragma once #include "Emu/RSX/GL/GLTexture.h" #include "GLRenderTargets.h" #include "glutils/blitter.h" #include "glutils/sync.hpp" #include "../Common/texture_cache.h" #include <memory> #include <vector> class GLGSRender; namespace gl { class cached_texture_section; class texture_cache; struct texture_cache_traits { using commandbuffer_type = gl::command_context; using section_storage_type = gl::cached_texture_section; using texture_cache_type = gl::texture_cache; using texture_cache_base_type = rsx::texture_cache<texture_cache_type, texture_cache_traits>; using image_resource_type = gl::texture*; using image_view_type = gl::texture_view*; using image_storage_type = gl::texture; using texture_format = gl::texture::format; using viewable_image_type = gl::viewable_image*; }; class cached_texture_section : public rsx::cached_texture_section<gl::cached_texture_section, gl::texture_cache_traits> { using baseclass = rsx::cached_texture_section<gl::cached_texture_section, gl::texture_cache_traits>; friend baseclass; fence m_fence; buffer pbo; gl::viewable_image* vram_texture = nullptr; std::unique_ptr<gl::viewable_image> managed_texture; std::unique_ptr<gl::texture> scaled_texture; texture::format format = texture::format::rgba; texture::type type = texture::type::ubyte; void init_buffer(const gl::texture* src) { const u32 vram_size = src->pitch() * src->height(); const u32 buffer_size = utils::align(vram_size, 4096); if (pbo) { if (pbo.size() >= buffer_size) return; pbo.remove(); } pbo.create(buffer::target::pixel_pack, buffer_size, nullptr, buffer::memory_type::host_visible, buffer::usage::host_read); glBindBuffer(GL_PIXEL_PACK_BUFFER, GL_NONE); } public: using baseclass::cached_texture_section; void create(u16 w, u16 h, u16 depth, u16 mipmaps, gl::texture* image, u32 rsx_pitch, bool managed, gl::texture::format gl_format = gl::texture::format::rgba, gl::texture::type gl_type = gl::texture::type::ubyte, bool swap_bytes = false) { if (vram_texture && !managed_texture && get_protection() == utils::protection::no) { // In-place image swap, still locked. Likely a color buffer that got rebound as depth buffer or vice-versa. gl::as_rtt(vram_texture)->on_swap_out(); if (!managed) { // Incoming is also an external resource, reference it immediately gl::as_rtt(image)->on_swap_in(is_locked()); } } auto new_texture = static_cast<gl::viewable_image*>(image); ensure(!exists() || !is_managed() || vram_texture == new_texture); vram_texture = new_texture; if (managed) { managed_texture.reset(vram_texture); } else { ensure(!managed_texture); } if (auto rtt = dynamic_cast<gl::render_target*>(image)) { swizzled = (rtt->raster_type != rsx::surface_raster_type::linear); } flushed = false; synchronized = false; sync_timestamp = 0ull; ensure(rsx_pitch); this->rsx_pitch = rsx_pitch; this->width = w; this->height = h; this->real_pitch = 0; this->depth = depth; this->mipmaps = mipmaps; set_format(gl_format, gl_type, swap_bytes); // Notify baseclass baseclass::on_section_resources_created(); } void set_dimensions(u32 width, u32 height, u32 /*depth*/, u32 pitch) { this->width = width; this->height = height; rsx_pitch = pitch; } void set_format(texture::format gl_format, texture::type gl_type, bool swap_bytes) { format = gl_format; type = gl_type; pack_unpack_swap_bytes = swap_bytes; if (format == gl::texture::format::rgba) { switch (type) { case gl::texture::type::f16: gcm_format = CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT; break; case gl::texture::type::f32: gcm_format = CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT; break; default: break; } } } void dma_transfer(gl::command_context& cmd, gl::texture* src, const areai& /*src_area*/, const utils::address_range& /*valid_range*/, u32 pitch) { init_buffer(src); glGetError(); if (context == rsx::texture_upload_context::dma) { // Determine unpack config dynamically const auto format_info = gl::get_format_type(src->get_internal_format()); format = static_cast<gl::texture::format>(format_info.format); type = static_cast<gl::texture::type>(format_info.type); pack_unpack_swap_bytes = format_info.swap_bytes; } real_pitch = src->pitch(); rsx_pitch = pitch; bool use_driver_pixel_transform = true; if (get_driver_caps().ARB_compute_shader_supported) [[likely]] { if (src->aspect() & image_aspect::depth) { buffer scratch_mem; // Invoke compute if (auto error = glGetError(); !error) [[likely]] { pixel_buffer_layout pack_info{}; image_memory_requirements mem_info{}; pack_info.format = static_cast<GLenum>(format); pack_info.type = static_cast<GLenum>(type); pack_info.size = (src->aspect() & image_aspect::stencil) ? 4 : 2; pack_info.swap_bytes = true; mem_info.image_size_in_texels = src->width() * src->height(); mem_info.image_size_in_bytes = src->pitch() * src->height(); mem_info.memory_required = 0; if (pack_info.type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV) { // D32FS8 can be read back as D24S8 or D32S8X24. In case of the latter, double memory requirements mem_info.image_size_in_bytes *= 2; } void* out_offset = copy_image_to_buffer(cmd, pack_info, src, &scratch_mem, 0, 0, { {}, src->size3D() }, &mem_info); glBindBuffer(GL_SHADER_STORAGE_BUFFER, GL_NONE); glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT); real_pitch = pack_info.size * src->width(); const u64 data_length = pack_info.size * mem_info.image_size_in_texels; scratch_mem.copy_to(&pbo, reinterpret_cast<u64>(out_offset), 0, data_length); } else { rsx_log.error("Memory transfer failed with error 0x%x. Format=0x%x, Type=0x%x", error, static_cast<u32>(format), static_cast<u32>(type)); } scratch_mem.remove(); use_driver_pixel_transform = false; } } if (use_driver_pixel_transform) { if (src->aspect() & image_aspect::stencil) { pack_unpack_swap_bytes = false; } pbo.bind(buffer::target::pixel_pack); pixel_pack_settings pack_settings; pack_settings.alignment(1); pack_settings.swap_bytes(pack_unpack_swap_bytes); src->copy_to(nullptr, format, type, pack_settings); } if (auto error = glGetError()) { if (error == GL_OUT_OF_MEMORY && ::gl::get_driver_caps().vendor_AMD) { // AMD driver bug // Pixel transfer fails with GL_OUT_OF_MEMORY. Usually happens with float textures or operations attempting to swap endianness. // Failed operations also leak a large amount of memory rsx_log.error("Memory transfer failure (AMD bug). Please update your driver to Adrenalin 19.4.3 or newer. Format=0x%x, Type=0x%x, Swap=%d", static_cast<u32>(format), static_cast<u32>(type), pack_unpack_swap_bytes); } else { rsx_log.error("Memory transfer failed with error 0x%x. Format=0x%x, Type=0x%x", error, static_cast<u32>(format), static_cast<u32>(type)); } } glBindBuffer(GL_PIXEL_PACK_BUFFER, GL_NONE); m_fence.reset(); synchronized = true; sync_timestamp = rsx::get_shared_tag(); } void copy_texture(gl::command_context& cmd, bool miss) { ensure(exists()); if (!miss) [[likely]] { baseclass::on_speculative_flush(); } else { baseclass::on_miss(); } if (context == rsx::texture_upload_context::framebuffer_storage) { auto as_rtt = static_cast<gl::render_target*>(vram_texture); if (as_rtt->dirty()) as_rtt->read_barrier(cmd); } gl::texture* target_texture = vram_texture; if ((rsx::get_resolution_scale_percent() != 100 && context == rsx::texture_upload_context::framebuffer_storage) || (vram_texture->pitch() != rsx_pitch)) { u32 real_width = width; u32 real_height = height; if (context == rsx::texture_upload_context::framebuffer_storage) { auto surface = gl::as_rtt(vram_texture); real_width *= surface->samples_x; real_height *= surface->samples_y; } areai src_area = { 0, 0, 0, 0 }; const areai dst_area = { 0, 0, static_cast<s32>(real_width), static_cast<s32>(real_height) }; auto ifmt = vram_texture->get_internal_format(); src_area.x2 = vram_texture->width(); src_area.y2 = vram_texture->height(); if (src_area.x2 != dst_area.x2 || src_area.y2 != dst_area.y2) { if (scaled_texture) { auto sfmt = scaled_texture->get_internal_format(); if (scaled_texture->width() != real_width || scaled_texture->height() != real_height || sfmt != ifmt) { //Discard current scaled texture scaled_texture.reset(); } } if (!scaled_texture) { scaled_texture = std::make_unique<gl::texture>(GL_TEXTURE_2D, real_width, real_height, 1, 1, static_cast<GLenum>(ifmt)); } const bool linear_interp = is_depth_texture() ? false : true; g_hw_blitter->scale_image(cmd, vram_texture, scaled_texture.get(), src_area, dst_area, linear_interp, {}); target_texture = scaled_texture.get(); } } dma_transfer(cmd, target_texture, {}, {}, rsx_pitch); } /** * Flush */ void* map_synchronized(u32 offset, u32 size) { AUDIT(synchronized && !m_fence.is_empty()); m_fence.wait_for_signal(); ensure(offset + GLsizeiptr{size} <= pbo.size()); return pbo.map(offset, size, gl::buffer::access::read); } void finish_flush(); /** * Misc */ void destroy() { if (!is_locked() && !pbo && vram_texture == nullptr && m_fence.is_empty() && !managed_texture) //Already destroyed return; if (pbo) { // Destroy pbo cache since vram texture is managed elsewhere pbo.remove(); scaled_texture.reset(); } managed_texture.reset(); vram_texture = nullptr; if (!m_fence.is_empty()) { m_fence.destroy(); } baseclass::on_section_resources_destroyed(); } void sync_surface_memory(const std::vector<cached_texture_section*>& surfaces) { auto rtt = gl::as_rtt(vram_texture); rtt->sync_tag(); for (auto& surface : surfaces) { rtt->inherit_surface_contents(gl::as_rtt(surface->vram_texture)); } } bool exists() const { return (vram_texture != nullptr); } bool is_managed() const { return !exists() || managed_texture; } texture::format get_format() const { return format; } gl::texture_view* get_view(const rsx::texture_channel_remap_t& remap) { return vram_texture->get_view(remap); } gl::viewable_image* get_raw_texture() const { return managed_texture.get(); } gl::render_target* get_render_target() const { return gl::as_rtt(vram_texture); } gl::texture_view* get_raw_view() { return vram_texture->get_view(rsx::default_remap_vector.with_encoding(GL_REMAP_IDENTITY)); } bool is_depth_texture() const { return !!(vram_texture->aspect() & gl::image_aspect::depth); } bool has_compatible_format(gl::texture* tex) const { //TODO return (tex->get_internal_format() == vram_texture->get_internal_format()); } }; class texture_cache : public rsx::texture_cache<gl::texture_cache, gl::texture_cache_traits> { private: using baseclass = rsx::texture_cache<gl::texture_cache, gl::texture_cache_traits>; friend baseclass; struct temporary_image_t : public gl::viewable_image, public rsx::ref_counted { u64 properties_encoding = 0; using gl::viewable_image::viewable_image; }; blitter m_hw_blitter; std::vector<std::unique_ptr<temporary_image_t>> m_temporary_surfaces; const u32 max_cached_image_pool_size = 256; private: void clear() { baseclass::clear(); clear_temporary_subresources(); } void clear_temporary_subresources() { m_temporary_surfaces.clear(); } gl::texture_view* create_temporary_subresource_impl(gl::command_context& cmd, gl::texture* src, GLenum sized_internal_fmt, GLenum dst_type, u32 gcm_format, u16 x, u16 y, u16 width, u16 height, u16 depth, u8 mipmaps, const rsx::texture_channel_remap_t& remap, bool copy); std::array<GLenum, 4> get_component_mapping(u32 gcm_format, rsx::component_order flags) const { switch (gcm_format) { case CELL_GCM_TEXTURE_DEPTH24_D8: case CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT: case CELL_GCM_TEXTURE_DEPTH16: case CELL_GCM_TEXTURE_DEPTH16_FLOAT: //Dont bother letting this propagate return{ GL_RED, GL_RED, GL_RED, GL_RED }; default: break; } switch (flags) { case rsx::component_order::default_: { return gl::get_swizzle_remap(gcm_format); } case rsx::component_order::native: { return{ GL_ALPHA, GL_RED, GL_GREEN, GL_BLUE }; } case rsx::component_order::swapped_native: { return{ GL_BLUE, GL_ALPHA, GL_RED, GL_GREEN }; } default: fmt::throw_exception("Unknown texture create flags"); } } void copy_transfer_regions_impl(gl::command_context& cmd, gl::texture* dst_image, const std::vector<copy_region_descriptor>& sources) const; gl::texture* get_template_from_collection_impl(const std::vector<copy_region_descriptor>& sections_to_transfer) const { if (sections_to_transfer.size() == 1) [[likely]] { return sections_to_transfer.front().src; } gl::texture* result = nullptr; for (const auto &section : sections_to_transfer) { if (!section.src) continue; if (!result) { result = section.src; } else { const auto set1 = result->get_native_component_layout(); const auto set2 = section.src->get_native_component_layout(); if (set1[0] != set2[0] || set1[1] != set2[1] || set1[2] != set2[2] || set1[3] != set2[3]) { // TODO // This requires a far more complex setup as its not always possible to mix and match without compute assistance return nullptr; } } } return result; } protected: gl::texture_view* create_temporary_subresource_view(gl::command_context& cmd, gl::texture** src, u32 gcm_format, u16 x, u16 y, u16 w, u16 h, const rsx::texture_channel_remap_t& remap_vector) override { return create_temporary_subresource_impl(cmd, *src, GL_NONE, GL_TEXTURE_2D, gcm_format, x, y, w, h, 1, 1, remap_vector, true); } gl::texture_view* create_temporary_subresource_view(gl::command_context& cmd, gl::texture* src, u32 gcm_format, u16 x, u16 y, u16 w, u16 h, const rsx::texture_channel_remap_t& remap_vector) override { return create_temporary_subresource_impl(cmd, src, static_cast<GLenum>(src->get_internal_format()), GL_TEXTURE_2D, gcm_format, x, y, w, h, 1, 1, remap_vector, true); } gl::texture_view* generate_cubemap_from_images(gl::command_context& cmd, u32 gcm_format, u16 size, const std::vector<copy_region_descriptor>& sources, const rsx::texture_channel_remap_t& remap_vector) override { auto _template = get_template_from_collection_impl(sources); auto result = create_temporary_subresource_impl(cmd, _template, GL_NONE, GL_TEXTURE_CUBE_MAP, gcm_format, 0, 0, size, size, 1, 1, remap_vector, false); copy_transfer_regions_impl(cmd, result->image(), sources); return result; } gl::texture_view* generate_3d_from_2d_images(gl::command_context& cmd, u32 gcm_format, u16 width, u16 height, u16 depth, const std::vector<copy_region_descriptor>& sources, const rsx::texture_channel_remap_t& remap_vector) override { auto _template = get_template_from_collection_impl(sources); auto result = create_temporary_subresource_impl(cmd, _template, GL_NONE, GL_TEXTURE_3D, gcm_format, 0, 0, width, height, depth, 1, remap_vector, false); copy_transfer_regions_impl(cmd, result->image(), sources); return result; } gl::texture_view* generate_atlas_from_images(gl::command_context& cmd, u32 gcm_format, u16 width, u16 height, const std::vector<copy_region_descriptor>& sections_to_copy, const rsx::texture_channel_remap_t& remap_vector) override { auto _template = get_template_from_collection_impl(sections_to_copy); auto result = create_temporary_subresource_impl(cmd, _template, GL_NONE, GL_TEXTURE_2D, gcm_format, 0, 0, width, height, 1, 1, remap_vector, false); copy_transfer_regions_impl(cmd, result->image(), sections_to_copy); return result; } gl::texture_view* generate_2d_mipmaps_from_images(gl::command_context& cmd, u32 gcm_format, u16 width, u16 height, const std::vector<copy_region_descriptor>& sections_to_copy, const rsx::texture_channel_remap_t& remap_vector) override { const auto mipmaps = ::narrow<u8>(sections_to_copy.size()); auto _template = get_template_from_collection_impl(sections_to_copy); auto result = create_temporary_subresource_impl(cmd, _template, GL_NONE, GL_TEXTURE_2D, gcm_format, 0, 0, width, height, 1, mipmaps, remap_vector, false); copy_transfer_regions_impl(cmd, result->image(), sections_to_copy); return result; } void release_temporary_subresource(gl::texture_view* view) override { for (auto& e : m_temporary_surfaces) { if (e.get() == view->image()) { e->release(); return; } } } void update_image_contents(gl::command_context& cmd, gl::texture_view* dst, gl::texture* src, u16 width, u16 height) override { std::vector<copy_region_descriptor> region = {{ .src = src, .xform = rsx::surface_transform::identity, .src_w = width, .src_h = height, .dst_w = width, .dst_h = height }}; copy_transfer_regions_impl(cmd, dst->image(), region); } cached_texture_section* create_new_texture(gl::command_context& cmd, const utils::address_range &rsx_range, u16 width, u16 height, u16 depth, u16 mipmaps, u32 pitch, u32 gcm_format, rsx::texture_upload_context context, rsx::texture_dimension_extended type, bool swizzled, rsx::component_order swizzle_flags, rsx::flags32_t /*flags*/) override { const rsx::image_section_attributes_t search_desc = { .gcm_format = gcm_format, .width = width, .height = height, .depth = depth, .mipmaps = mipmaps }; const bool allow_dirty = (context != rsx::texture_upload_context::framebuffer_storage); auto& cached = *find_cached_texture(rsx_range, search_desc, true, true, allow_dirty); ensure(!cached.is_locked()); gl::viewable_image* image = nullptr; if (cached.exists()) { // Try and reuse this image data. It is very likely to match our needs image = dynamic_cast<gl::viewable_image*>(cached.get_raw_texture()); if (!image || cached.get_image_type() != type) { // Type mismatch, discard cached.destroy(); image = nullptr; } else { ensure(cached.is_managed()); cached.set_dimensions(width, height, depth, pitch); cached.set_format(texture::format::rgba, texture::type::ubyte, true); // Clear the image before use if it is not going to be uploaded wholly from CPU if (context != rsx::texture_upload_context::shader_read) { if (image->format_class() == RSX_FORMAT_CLASS_COLOR) { g_hw_blitter->fast_clear_image(cmd, image, color4f{}); } else { g_hw_blitter->fast_clear_image(cmd, image, 1.f, 0); } } } } if (!image) { ensure(!cached.exists()); image = gl::create_texture(gcm_format, width, height, depth, mipmaps, type); // Prepare section cached.reset(rsx_range); cached.set_image_type(type); cached.set_gcm_format(gcm_format); cached.create(width, height, depth, mipmaps, image, pitch, true); } cached.set_view_flags(swizzle_flags); cached.set_context(context); cached.set_swizzled(swizzled); cached.set_dirty(false); const auto swizzle = get_component_mapping(gcm_format, swizzle_flags); image->set_native_component_layout(swizzle); if (context != rsx::texture_upload_context::blit_engine_dst) { AUDIT(cached.get_memory_read_flags() != rsx::memory_read_flags::flush_always); read_only_range = cached.get_min_max(read_only_range, rsx::section_bounds::locked_range); // TODO ruipin: This was outside the if, but is inside the if in Vulkan. Ask kd-11 cached.protect(utils::protection::ro); } else { //TODO: More tests on byte order //ARGB8+native+unswizzled is confirmed with Dark Souls II character preview switch (gcm_format) { case CELL_GCM_TEXTURE_A8R8G8B8: { cached.set_format(gl::texture::format::bgra, gl::texture::type::uint_8_8_8_8_rev, true); break; } case CELL_GCM_TEXTURE_R5G6B5: { cached.set_format(gl::texture::format::rgb, gl::texture::type::ushort_5_6_5, true); break; } case CELL_GCM_TEXTURE_DEPTH24_D8: { cached.set_format(gl::texture::format::depth_stencil, gl::texture::type::uint_24_8, false); break; } case CELL_GCM_TEXTURE_DEPTH16: { cached.set_format(gl::texture::format::depth, gl::texture::type::ushort, true); break; } default: fmt::throw_exception("Unexpected gcm format 0x%X", gcm_format); } //NOTE: Protection is handled by the caller cached.set_dimensions(width, height, depth, (rsx_range.length() / height)); no_access_range = cached.get_min_max(no_access_range, rsx::section_bounds::locked_range); } update_cache_tag(); return &cached; } cached_texture_section* create_nul_section( gl::command_context& /*cmd*/, const utils::address_range& rsx_range, const rsx::image_section_attributes_t& attrs, const rsx::GCM_tile_reference& /*tile*/, bool /*memory_load*/) override { auto& cached = *find_cached_texture(rsx_range, { .gcm_format = RSX_GCM_FORMAT_IGNORED }, true, false, false); ensure(!cached.is_locked()); // Prepare section cached.reset(rsx_range); cached.create_dma_only(attrs.width, attrs.height, attrs.pitch); cached.set_dirty(false); no_access_range = cached.get_min_max(no_access_range, rsx::section_bounds::locked_range); update_cache_tag(); return &cached; } cached_texture_section* upload_image_from_cpu(gl::command_context& cmd, const utils::address_range& rsx_range, u16 width, u16 height, u16 depth, u16 mipmaps, u32 pitch, u32 gcm_format, rsx::texture_upload_context context, const std::vector<rsx::subresource_layout>& subresource_layout, rsx::texture_dimension_extended type, bool input_swizzled) override { auto section = create_new_texture(cmd, rsx_range, width, height, depth, mipmaps, pitch, gcm_format, context, type, input_swizzled, rsx::component_order::default_, 0); gl::upload_texture(cmd, section->get_raw_texture(), gcm_format, input_swizzled, subresource_layout); section->last_write_tag = rsx::get_shared_tag(); return section; } void set_component_order(cached_texture_section& section, u32 gcm_format, rsx::component_order flags) override { if (flags == section.get_view_flags()) return; const auto swizzle = get_component_mapping(gcm_format, flags); auto image = static_cast<gl::viewable_image*>(section.get_raw_texture()); ensure(image); image->set_native_component_layout(swizzle); section.set_view_flags(flags); } void insert_texture_barrier(gl::command_context&, gl::texture*, bool) override { auto &caps = gl::get_driver_caps(); if (caps.ARB_texture_barrier_supported) glTextureBarrier(); else if (caps.NV_texture_barrier_supported) glTextureBarrierNV(); } bool render_target_format_is_compatible(gl::texture* tex, u32 gcm_format) override { auto ifmt = tex->get_internal_format(); switch (gcm_format) { default: // TODO err_once("Format incompatibility detected, reporting failure to force data copy (GL_INTERNAL_FORMAT=0x%X, GCM_FORMAT=0x%X)", static_cast<u32>(ifmt), gcm_format); return false; case CELL_GCM_TEXTURE_W16_Z16_Y16_X16_FLOAT: return (ifmt == gl::texture::internal_format::rgba16f); case CELL_GCM_TEXTURE_W32_Z32_Y32_X32_FLOAT: return (ifmt == gl::texture::internal_format::rgba32f); case CELL_GCM_TEXTURE_X32_FLOAT: return (ifmt == gl::texture::internal_format::r32f); case CELL_GCM_TEXTURE_R5G6B5: return (ifmt == gl::texture::internal_format::rgb565); case CELL_GCM_TEXTURE_A8R8G8B8: case CELL_GCM_TEXTURE_D8R8G8B8: return (ifmt == gl::texture::internal_format::bgra8 || ifmt == gl::texture::internal_format::depth24_stencil8 || ifmt == gl::texture::internal_format::depth32f_stencil8); case CELL_GCM_TEXTURE_B8: return (ifmt == gl::texture::internal_format::r8); case CELL_GCM_TEXTURE_G8B8: return (ifmt == gl::texture::internal_format::rg8); case CELL_GCM_TEXTURE_DEPTH24_D8: case CELL_GCM_TEXTURE_DEPTH24_D8_FLOAT: return (ifmt == gl::texture::internal_format::depth24_stencil8 || ifmt == gl::texture::internal_format::depth32f_stencil8); case CELL_GCM_TEXTURE_X16: case CELL_GCM_TEXTURE_DEPTH16: case CELL_GCM_TEXTURE_DEPTH16_FLOAT: return (ifmt == gl::texture::internal_format::depth16 || ifmt == gl::texture::internal_format::depth32f); } } void prepare_for_dma_transfers(gl::command_context&) override {} void cleanup_after_dma_transfers(gl::command_context&) override {} public: using baseclass::texture_cache; void initialize() { m_hw_blitter.init(); g_hw_blitter = &m_hw_blitter; } void destroy() override { clear(); g_hw_blitter = nullptr; m_hw_blitter.destroy(); } bool is_depth_texture(u32 rsx_address, u32 rsx_size) override { reader_lock lock(m_cache_mutex); auto &block = m_storage.block_for(rsx_address); if (block.get_locked_count() == 0) return false; for (auto& tex : block) { if (tex.is_dirty()) continue; if (!tex.overlaps(rsx_address, rsx::section_bounds::full_range)) continue; if ((rsx_address + rsx_size - tex.get_section_base()) <= tex.get_section_size()) return tex.is_depth_texture(); } return false; } void on_frame_end() override { trim_sections(); if (m_storage.m_unreleased_texture_objects >= m_max_zombie_objects) { purge_unreleased_sections(); } if (m_temporary_surfaces.size() > max_cached_image_pool_size) { m_temporary_surfaces.resize(max_cached_image_pool_size / 2); } baseclass::on_frame_end(); } bool blit(gl::command_context& cmd, const rsx::blit_src_info& src, const rsx::blit_dst_info& dst, bool linear_interpolate, gl_render_targets& m_rtts) { auto result = upload_scaled_image(src, dst, linear_interpolate, cmd, m_rtts, m_hw_blitter); if (result.succeeded) { if (result.real_dst_size) { flush_if_cache_miss_likely(cmd, result.to_address_range()); } return true; } return false; } }; }
26,996
C++
.h
733
32.3206
233
0.676855
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,131
GLProgramBuffer.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLProgramBuffer.h
#pragma once #include "GLVertexProgram.h" #include "GLFragmentProgram.h" #include "GLHelpers.h" #include "GLPipelineCompiler.h" #include "../Program/ProgramStateCache.h" #include "../rsx_utils.h" struct GLTraits { using vertex_program_type = GLVertexProgram; using fragment_program_type = GLFragmentProgram; using pipeline_type = gl::glsl::program; using pipeline_storage_type = std::unique_ptr<gl::glsl::program>; using pipeline_properties = void*; static void recompile_fragment_program(const RSXFragmentProgram &RSXFP, fragment_program_type& fragmentProgramData, usz /*ID*/) { fragmentProgramData.Decompile(RSXFP); } static void recompile_vertex_program(const RSXVertexProgram &RSXVP, vertex_program_type& vertexProgramData, usz /*ID*/) { vertexProgramData.Decompile(RSXVP); } static void validate_pipeline_properties(const vertex_program_type&, const fragment_program_type&, pipeline_properties&) { } static pipeline_type* build_pipeline( const vertex_program_type &vertexProgramData, const fragment_program_type &fragmentProgramData, const pipeline_properties&, bool compile_async, std::function<pipeline_type*(pipeline_storage_type&)> callback) { auto compiler = gl::get_pipe_compiler(); auto flags = (compile_async) ? gl::pipe_compiler::COMPILE_DEFERRED : gl::pipe_compiler::COMPILE_INLINE; auto post_create_func = [vp = &vertexProgramData.shader, fp = &fragmentProgramData.shader] (gl::glsl::program* program) { if (!vp->compiled()) { const_cast<gl::glsl::shader*>(vp)->compile(); } if (!fp->compiled()) { const_cast<gl::glsl::shader*>(fp)->compile(); } program->attach(*vp) .attach(*fp) .bind_fragment_data_location("ocol0", 0) .bind_fragment_data_location("ocol1", 1) .bind_fragment_data_location("ocol2", 2) .bind_fragment_data_location("ocol3", 3); if (g_cfg.video.log_programs) { rsx_log.notice("*** prog id = %d", program->id()); rsx_log.notice("*** vp id = %d", vp->id()); rsx_log.notice("*** fp id = %d", fp->id()); } }; auto post_link_func = [](gl::glsl::program* program) { // Program locations are guaranteed to not change after linking // Texture locations are simply bound to the TIUs so this can be done once for (int i = 0; i < rsx::limits::fragment_textures_count; ++i) { int location; if (program->uniforms.has_location(rsx::constants::fragment_texture_names[i], &location)) { // Assign location to TIU program->uniforms[location] = GL_FRAGMENT_TEXTURES_START + i; // Check for stencil mirror const std::string mirror_name = std::string(rsx::constants::fragment_texture_names[i]) + "_stencil"; if (program->uniforms.has_location(mirror_name, &location)) { // Assign mirror to TIU program->uniforms[location] = GL_STENCIL_MIRRORS_START + i; } } } for (int i = 0; i < rsx::limits::vertex_textures_count; ++i) { int location; if (program->uniforms.has_location(rsx::constants::vertex_texture_names[i], &location)) program->uniforms[location] = GL_VERTEX_TEXTURES_START + i; } // Bind locations 0 and 1 to the stream buffers program->uniforms[0] = GL_STREAM_BUFFER_START + 0; program->uniforms[1] = GL_STREAM_BUFFER_START + 1; }; auto pipeline = compiler->compile(flags, post_create_func, post_link_func, callback); return callback(pipeline); } }; struct GLProgramBuffer : public program_state_cache<GLTraits> { GLProgramBuffer() = default; void initialize(decompiler_callback_t callback) { notify_pipeline_compiled = callback; } u64 get_hash(void* const&) { return 0; } u64 get_hash(const RSXVertexProgram &prog) { return program_hash_util::vertex_program_utils::get_vertex_program_ucode_hash(prog); } u64 get_hash(const RSXFragmentProgram &prog) { return program_hash_util::fragment_program_utils::get_fragment_program_ucode_hash(prog); } template <typename... Args> void add_pipeline_entry(const RSXVertexProgram& vp, const RSXFragmentProgram& fp, void* &props, Args&& ...args) { get_graphics_pipeline(vp, fp, props, false, false, std::forward<Args>(args)...); } void preload_programs(const RSXVertexProgram& vp, const RSXFragmentProgram& fp) { search_vertex_program(vp); search_fragment_program(fp); } bool check_cache_missed() const { return m_cache_miss_flag; } };
4,389
C++
.h
130
30.476923
121
0.713004
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,132
GLPipelineCompiler.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLPipelineCompiler.h
#pragma once #include "GLHelpers.h" #include "glutils/program.h" #include "Emu/RSX/display.h" #include "Utilities/lockless.h" namespace gl { class pipe_compiler { public: enum op_flags { COMPILE_DEFAULT = 0, COMPILE_INLINE = 1, COMPILE_DEFERRED = 2 }; using storage_callback_t = std::function<void(std::unique_ptr<glsl::program>&)>; using build_callback_t = std::function<void(glsl::program*)>; pipe_compiler(); ~pipe_compiler(); void initialize( std::function<draw_context_t()> context_create_func, std::function<void(draw_context_t)> context_bind_func, std::function<void(draw_context_t)> context_destroy_func); std::unique_ptr<glsl::program> compile( op_flags flags, build_callback_t post_create_func = {}, build_callback_t post_link_func = {}, storage_callback_t completion_callback = {}); void operator()(); private: struct pipe_compiler_job { build_callback_t post_create_func; build_callback_t post_link_func; storage_callback_t completion_callback; pipe_compiler_job(build_callback_t post_create, build_callback_t post_link, storage_callback_t completion) : post_create_func(post_create), post_link_func(post_link), completion_callback(completion) {} }; lf_queue<pipe_compiler_job> m_work_queue; draw_context_t m_context = 0; atomic_t<bool> m_context_ready = false; std::function<void(draw_context_t context)> m_context_bind_func; std::function<void(draw_context_t context)> m_context_destroy_func; std::unique_ptr<glsl::program> int_compile_graphics_pipe( build_callback_t post_create_func, build_callback_t post_link_func); }; void initialize_pipe_compiler( std::function<draw_context_t()> context_create_func, std::function<void(draw_context_t)> context_bind_func, std::function<void(draw_context_t)> context_destroy_func, int num_worker_threads = -1); void destroy_pipe_compiler(); pipe_compiler* get_pipe_compiler(); }
2,024
C++
.h
56
31.714286
110
0.711042
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,133
GLRenderTargets.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLRenderTargets.h
#pragma once #include "../Common/surface_store.h" #include "GLHelpers.h" #include "../rsx_utils.h" #include "glutils/fbo.h" struct color_swizzle { gl::texture::channel a = gl::texture::channel::a; gl::texture::channel r = gl::texture::channel::r; gl::texture::channel g = gl::texture::channel::g; gl::texture::channel b = gl::texture::channel::b; color_swizzle() = default; color_swizzle(gl::texture::channel a, gl::texture::channel r, gl::texture::channel g, gl::texture::channel b) : a(a), r(r), g(g), b(b) { } }; struct color_format { gl::texture::type type; gl::texture::format format; gl::texture::internal_format internal_format; bool swap_bytes; color_swizzle swizzle; }; struct depth_format { gl::texture::type type; gl::texture::format format; gl::texture::internal_format internal_format; }; namespace rsx { namespace internals { color_format surface_color_format_to_gl(rsx::surface_color_format color_format); depth_format surface_depth_format_to_gl(rsx::surface_depth_format2 depth_format); u8 get_pixel_size(rsx::surface_depth_format format); } } namespace gl { class render_target : public viewable_image, public rsx::render_target_descriptor<texture*> { void clear_memory(gl::command_context& cmd); void load_memory(gl::command_context& cmd); void initialize_memory(gl::command_context& cmd, rsx::surface_access access); public: render_target(GLuint width, GLuint height, GLenum sized_format, rsx::format_class format_class) : viewable_image(GL_TEXTURE_2D, width, height, 1, 1, sized_format, format_class) {} // Internal pitch is the actual row length in bytes of the openGL texture void set_native_pitch(u32 pitch) { native_pitch = pitch; } void set_surface_dimensions(u16 w, u16 h, u32 pitch) { surface_width = w; surface_height = h; rsx_pitch = pitch; } void set_rsx_pitch(u32 pitch) { rsx_pitch = pitch; } bool is_depth_surface() const override { return !!(aspect() & gl::image_aspect::depth); } viewable_image* get_surface(rsx::surface_access /*access_type*/) override { // TODO return static_cast<gl::viewable_image*>(this); } u32 raw_handle() const { return id(); } bool matches_dimensions(u16 _width, u16 _height) const { //Use forward scaling to account for rounding and clamping errors const auto [scaled_w, scaled_h] = rsx::apply_resolution_scale<true>(_width, _height); return (scaled_w == width()) && (scaled_h == height()); } void memory_barrier(gl::command_context& cmd, rsx::surface_access access); void read_barrier(gl::command_context& cmd) { memory_barrier(cmd, rsx::surface_access::shader_read); } void write_barrier(gl::command_context& cmd) { memory_barrier(cmd, rsx::surface_access::shader_write); } }; struct framebuffer_holder : public gl::fbo, public rsx::ref_counted { using gl::fbo::fbo; }; static inline gl::render_target* as_rtt(gl::texture* t) { return ensure(dynamic_cast<gl::render_target*>(t)); } static inline const gl::render_target* as_rtt(const gl::texture* t) { return ensure(dynamic_cast<const gl::render_target*>(t)); } } struct gl_render_target_traits { using surface_storage_type = std::unique_ptr<gl::render_target>; using surface_type = gl::render_target*; using buffer_object_storage_type = std::unique_ptr<gl::buffer>; using buffer_object_type = gl::buffer*; using command_list_type = gl::command_context&; using download_buffer_object = std::vector<u8>; using barrier_descriptor_t = rsx::deferred_clipped_region<gl::render_target*>; static std::unique_ptr<gl::render_target> create_new_surface( u32 address, rsx::surface_color_format surface_color_format, usz width, usz height, usz pitch, rsx::surface_antialiasing antialias ) { auto format = rsx::internals::surface_color_format_to_gl(surface_color_format); const auto [width_, height_] = rsx::apply_resolution_scale<true>(static_cast<u16>(width), static_cast<u16>(height)); std::unique_ptr<gl::render_target> result(new gl::render_target(width_, height_, static_cast<GLenum>(format.internal_format), RSX_FORMAT_CLASS_COLOR)); result->set_aa_mode(antialias); result->set_native_pitch(static_cast<u32>(width) * get_format_block_size_in_bytes(surface_color_format) * result->samples_x); result->set_surface_dimensions(static_cast<u16>(width), static_cast<u16>(height), static_cast<u32>(pitch)); result->set_format(surface_color_format); std::array<GLenum, 4> native_layout = { static_cast<GLenum>(format.swizzle.a), static_cast<GLenum>(format.swizzle.r), static_cast<GLenum>(format.swizzle.g), static_cast<GLenum>(format.swizzle.b) }; result->set_native_component_layout(native_layout); result->memory_usage_flags = rsx::surface_usage_flags::attachment; result->state_flags = rsx::surface_state_flags::erase_bkgnd; result->queue_tag(address); result->add_ref(); return result; } static std::unique_ptr<gl::render_target> create_new_surface( u32 address, rsx::surface_depth_format2 surface_depth_format, usz width, usz height, usz pitch, rsx::surface_antialiasing antialias ) { auto format = rsx::internals::surface_depth_format_to_gl(surface_depth_format); const auto [width_, height_] = rsx::apply_resolution_scale<true>(static_cast<u16>(width), static_cast<u16>(height)); std::unique_ptr<gl::render_target> result(new gl::render_target(width_, height_, static_cast<GLenum>(format.internal_format), rsx::classify_format(surface_depth_format))); result->set_aa_mode(antialias); result->set_surface_dimensions(static_cast<u16>(width), static_cast<u16>(height), static_cast<u32>(pitch)); result->set_format(surface_depth_format); result->set_native_pitch(static_cast<u32>(width) * get_format_block_size_in_bytes(surface_depth_format) * result->samples_x); std::array<GLenum, 4> native_layout = { GL_RED, GL_RED, GL_RED, GL_RED }; result->set_native_component_layout(native_layout); result->memory_usage_flags = rsx::surface_usage_flags::attachment; result->state_flags = rsx::surface_state_flags::erase_bkgnd; result->queue_tag(address); result->add_ref(); return result; } static void clone_surface( gl::command_context& cmd, std::unique_ptr<gl::render_target>& sink, gl::render_target* ref, u32 address, barrier_descriptor_t& prev) { if (!sink) { auto internal_format = static_cast<GLenum>(ref->get_internal_format()); const auto [new_w, new_h] = rsx::apply_resolution_scale<true>(prev.width, prev.height, ref->get_surface_width<rsx::surface_metrics::pixels>(), ref->get_surface_height<rsx::surface_metrics::pixels>()); sink = std::make_unique<gl::render_target>(new_w, new_h, internal_format, ref->format_class()); sink->add_ref(); sink->memory_usage_flags = rsx::surface_usage_flags::storage; sink->state_flags = rsx::surface_state_flags::erase_bkgnd; sink->format_info = ref->format_info; sink->set_spp(ref->get_spp()); sink->set_native_pitch(static_cast<u32>(prev.width) * ref->get_bpp() * ref->samples_x); sink->set_rsx_pitch(ref->get_rsx_pitch()); sink->set_surface_dimensions(prev.width, prev.height, ref->get_rsx_pitch()); sink->set_native_component_layout(ref->get_native_component_layout()); sink->queue_tag(address); } sink->on_clone_from(ref); if (!sink->old_contents.empty()) { // Deal with this, likely only needs to clear if (sink->surface_width > prev.width || sink->surface_height > prev.height) { sink->write_barrier(cmd); } else { sink->clear_rw_barrier(); } } prev.target = sink.get(); sink->set_old_contents_region(prev, false); } static std::unique_ptr<gl::render_target> convert_pitch( gl::command_context& /*cmd*/, std::unique_ptr<gl::render_target>& src, usz /*out_pitch*/) { // TODO src->state_flags = rsx::surface_state_flags::erase_bkgnd; return {}; } static bool is_compatible_surface(const gl::render_target* surface, const gl::render_target* ref, u16 width, u16 height, u8 sample_count) { return (surface->get_internal_format() == ref->get_internal_format() && surface->get_spp() == sample_count && surface->get_surface_width<rsx::surface_metrics::pixels>() == width && surface->get_surface_height<rsx::surface_metrics::pixels>() == height); } static void prepare_surface_for_drawing(gl::command_context&, gl::render_target* surface) { surface->memory_usage_flags |= rsx::surface_usage_flags::attachment; } static void prepare_surface_for_sampling(gl::command_context&, gl::render_target*) {} static bool surface_is_pitch_compatible(const std::unique_ptr<gl::render_target> &surface, usz pitch) { return surface->get_rsx_pitch() == pitch; } static void int_invalidate_surface_contents(gl::command_context&, gl::render_target *surface, u32 address, usz pitch) { surface->set_rsx_pitch(static_cast<u32>(pitch)); surface->queue_tag(address); surface->last_use_tag = 0; surface->stencil_init_flags = 0; surface->memory_usage_flags = rsx::surface_usage_flags::unknown; surface->raster_type = rsx::surface_raster_type::linear; } static void invalidate_surface_contents( gl::command_context& cmd, gl::render_target* surface, rsx::surface_color_format format, u32 address, usz pitch) { auto fmt = rsx::internals::surface_color_format_to_gl(format); std::array<GLenum, 4> native_layout = { static_cast<GLenum>(fmt.swizzle.a), static_cast<GLenum>(fmt.swizzle.r), static_cast<GLenum>(fmt.swizzle.g), static_cast<GLenum>(fmt.swizzle.b) }; surface->set_native_component_layout(native_layout); surface->set_format(format); int_invalidate_surface_contents(cmd, surface, address, pitch); } static void invalidate_surface_contents( gl::command_context& cmd, gl::render_target* surface, rsx::surface_depth_format2 format, u32 address, usz pitch) { surface->set_format(format); int_invalidate_surface_contents(cmd, surface, address, pitch); } static void notify_surface_invalidated(const std::unique_ptr<gl::render_target>& surface) { if (!surface->old_contents.empty()) { // TODO: Retire the deferred writes surface->clear_rw_barrier(); } surface->release(); } static void notify_surface_persist(const std::unique_ptr<gl::render_target>& /*surface*/) {} static void notify_surface_reused(const std::unique_ptr<gl::render_target>& surface) { surface->state_flags |= rsx::surface_state_flags::erase_bkgnd; surface->add_ref(); } static bool int_surface_matches_properties( const std::unique_ptr<gl::render_target> &surface, gl::texture::internal_format format, usz width, usz height, rsx::surface_antialiasing antialias, bool check_refs = false) { if (check_refs && surface->has_refs()) return false; return surface->get_internal_format() == format && surface->get_spp() == get_format_sample_count(antialias) && surface->matches_dimensions(static_cast<u16>(width), static_cast<u16>(height)); } static bool surface_matches_properties( const std::unique_ptr<gl::render_target> &surface, rsx::surface_color_format format, usz width, usz height, rsx::surface_antialiasing antialias, bool check_refs=false) { const auto internal_fmt = rsx::internals::surface_color_format_to_gl(format).internal_format; return int_surface_matches_properties(surface, internal_fmt, width, height, antialias, check_refs); } static bool surface_matches_properties( const std::unique_ptr<gl::render_target> &surface, rsx::surface_depth_format2 format, usz width, usz height, rsx::surface_antialiasing antialias, bool check_refs = false) { const auto internal_fmt = rsx::internals::surface_depth_format_to_gl(format).internal_format; return int_surface_matches_properties(surface, internal_fmt, width, height, antialias, check_refs); } static void spill_buffer(std::unique_ptr<gl::buffer>& /*bo*/) { // TODO } static void unspill_buffer(std::unique_ptr<gl::buffer>& /*bo*/) { // TODO } static void write_render_target_to_memory( gl::command_context&, gl::buffer*, gl::render_target*, u64, u64, u64) { // TODO } template <int BlockSize> static gl::buffer* merge_bo_list(gl::command_context&, const std::vector<gl::buffer*>& /*list*/) { // TODO return nullptr; } template <typename T> static T* get(const std::unique_ptr<T> &in) { return in.get(); } }; struct gl_render_targets : public rsx::surface_store<gl_render_target_traits> { void destroy() { invalidate_all(); invalidated_resources.clear(); } std::vector<GLuint> trim(gl::command_context& cmd) { run_cleanup_internal(cmd, rsx::problem_severity::moderate, 256, [](gl::command_context&) {}); std::vector<GLuint> removed; invalidated_resources.remove_if([&](auto &rtt) { if (rtt->unused_check_count() >= 2) { removed.push_back(rtt->id()); return true; } return false; }); return removed; } };
12,934
C++
.h
375
31.645333
199
0.719568
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,134
GLTexture.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLTexture.h
#pragma once #include "OpenGL.h" #include "../GCM.h" #include "../Common/TextureUtils.h" #include "GLHelpers.h" #include <unordered_map> namespace rsx { class vertex_texture; class fragment_texture; } namespace gl { struct pixel_buffer_layout { GLenum format; GLenum type; u8 size; bool swap_bytes; u8 alignment; }; struct image_memory_requirements { u64 image_size_in_texels; u64 image_size_in_bytes; u64 memory_required; }; struct clear_cmd_info { GLbitfield aspect_mask = 0; struct { f32 value; } clear_depth{}; struct { u8 mask; u8 value; } clear_stencil{}; struct { u32 mask; u8 attachment_count; u8 r; u8 g; u8 b; u8 a; } clear_color{}; }; GLenum get_target(rsx::texture_dimension_extended type); GLenum get_sized_internal_format(u32 texture_format); std::tuple<GLenum, GLenum> get_format_type(u32 texture_format); pixel_buffer_layout get_format_type(texture::internal_format format); std::array<GLenum, 4> get_swizzle_remap(u32 texture_format); viewable_image* create_texture(u32 gcm_format, u16 width, u16 height, u16 depth, u16 mipmaps, rsx::texture_dimension_extended type); bool formats_are_bitcast_compatible(const texture* texture1, const texture* texture2); void copy_typeless(gl::command_context& cmd, texture* dst, const texture* src, const coord3u& dst_region, const coord3u& src_region); void copy_typeless(gl::command_context& cmd, texture* dst, const texture* src); void* copy_image_to_buffer(gl::command_context& cmd, const pixel_buffer_layout& pack_info, const gl::texture* src, gl::buffer* dst, u32 dst_offset, const int src_level, const coord3u& src_region, image_memory_requirements* mem_info); void copy_buffer_to_image(gl::command_context& cmd, const pixel_buffer_layout& unpack_info, gl::buffer* src, gl::texture* dst, const void* src_offset, const int dst_level, const coord3u& dst_region, image_memory_requirements* mem_info); void upload_texture(gl::command_context& cmd, texture* dst, u32 gcm_format, bool is_swizzled, const std::vector<rsx::subresource_layout>& subresources_layout); void clear_attachments(gl::command_context& cmd, const clear_cmd_info& info); namespace debug { extern std::unique_ptr<texture> g_vis_texture; } void destroy_global_texture_resources(); }
2,336
C++
.h
73
29.342466
160
0.742539
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,135
GLCompute.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLCompute.h
#pragma once #include "Emu/IdManager.h" #include "GLHelpers.h" #include "glutils/program.h" #include "../rsx_utils.h" #include <unordered_map> namespace gl { struct compute_task { std::string m_src; gl::glsl::shader m_shader; gl::glsl::program m_program; bool compiled = false; bool initialized = false; // Device-specific options bool unroll_loops = true; u32 optimal_group_size = 1; u32 optimal_kernel_size = 1; u32 max_invocations_x = 65535; virtual ~compute_task() = default; void initialize(); void create(); virtual void destroy(); virtual void bind_resources() {} void run(gl::command_context& cmd, u32 invocations_x, u32 invocations_y); void run(gl::command_context& cmd, u32 num_invocations); }; struct cs_shuffle_base : compute_task { const gl::buffer* m_data = nullptr; u32 m_data_offset = 0; u32 m_data_length = 0; u32 kernel_size = 1; std::string uniforms, variables, work_kernel, loop_advance, suffix, method_declarations; cs_shuffle_base(); virtual ~cs_shuffle_base() = default; void build(const char* function_name, u32 _kernel_size = 0); void bind_resources() override; void run(gl::command_context& cmd, const gl::buffer* data, u32 data_length, u32 data_offset = 0); }; struct cs_shuffle_16 final : cs_shuffle_base { // byteswap ushort cs_shuffle_16() { cs_shuffle_base::build("bswap_u16"); } }; struct cs_shuffle_32 final : cs_shuffle_base { // byteswap_ulong cs_shuffle_32() { cs_shuffle_base::build("bswap_u32"); } }; struct cs_shuffle_32_16 final : cs_shuffle_base { // byteswap_ulong + byteswap_ushort cs_shuffle_32_16() { cs_shuffle_base::build("bswap_u16_u32"); } }; template <bool SwapBytes> struct cs_shuffle_d32fx8_to_x8d24f final : cs_shuffle_base { u32 m_ssbo_length = 0; cs_shuffle_d32fx8_to_x8d24f(); void bind_resources() override; void run(gl::command_context& cmd, const gl::buffer* data, u32 src_offset, u32 dst_offset, u32 num_texels); }; template <bool SwapBytes> struct cs_shuffle_x8d24f_to_d32fx8 final : cs_shuffle_base { u32 m_ssbo_length = 0; cs_shuffle_x8d24f_to_d32fx8(); void bind_resources() override; void run(gl::command_context& cmd, const gl::buffer* data, u32 src_offset, u32 dst_offset, u32 num_texels); }; template <typename From, typename To, bool _SwapSrc = false, bool _SwapDst = false> struct cs_fconvert_task final : cs_shuffle_base { u32 m_ssbo_length = 0; void declare_f16_expansion() { method_declarations += "uvec2 unpack_e4m12_pack16(const in uint value)\n" "{\n" " uvec2 result = uvec2(bitfieldExtract(value, 0, 16), bitfieldExtract(value, 16, 16));\n" " result <<= 11;\n" " result += (120 << 23);\n" " return result;\n" "}\n\n"; } void declare_f16_contraction() { method_declarations += "uint pack_e4m12_pack16(const in uvec2 value)\n" "{\n" " uvec2 result = (value - (120 << 23)) >> 11;\n" " return (result.x & 0xFFFF) | (result.y << 16);\n" "}\n\n"; } cs_fconvert_task() { uniforms = "uniform uint data_length_in_bytes, in_ptr, out_ptr;\n"; variables = " uint block_length = data_length_in_bytes >> 2;\n" " uint in_offset = in_ptr >> 2;\n" " uint out_offset = out_ptr >> 2;\n" " uvec4 tmp;\n"; work_kernel = " if (index >= block_length)\n" " return;\n"; if constexpr (sizeof(From) == 4) { static_assert(sizeof(To) == 2); declare_f16_contraction(); work_kernel += " const uint src_offset = (index * 2) + in_offset;\n" " const uint dst_offset = index + out_offset;\n" " tmp.x = data[src_offset];\n" " tmp.y = data[src_offset + 1];\n"; if constexpr (_SwapSrc) { work_kernel += " tmp = bswap_u32(tmp);\n"; } // Convert work_kernel += " tmp.z = pack_e4m12_pack16(tmp.xy);\n"; if constexpr (_SwapDst) { work_kernel += " tmp.z = bswap_u16(tmp.z);\n"; } work_kernel += " data[dst_offset] = tmp.z;\n"; } else { static_assert(sizeof(To) == 4); declare_f16_expansion(); work_kernel += " const uint src_offset = index + in_offset;\n" " const uint dst_offset = (index * 2) + out_offset;\n" " tmp.x = data[src_offset];\n"; if constexpr (_SwapSrc) { work_kernel += " tmp.x = bswap_u16(tmp.x);\n"; } // Convert work_kernel += " tmp.yz = unpack_e4m12_pack16(tmp.x);\n"; if constexpr (_SwapDst) { work_kernel += " tmp.yz = bswap_u32(tmp.yz);\n"; } work_kernel += " data[dst_offset] = tmp.y;\n" " data[dst_offset + 1] = tmp.z;\n"; } cs_shuffle_base::build(""); } void bind_resources() override { m_data->bind_range(gl::buffer::target::ssbo, GL_COMPUTE_BUFFER_SLOT(0), m_data_offset, m_ssbo_length); } void run(gl::command_context& cmd, const gl::buffer* data, u32 src_offset, u32 src_length, u32 dst_offset) { u32 data_offset; if (src_offset > dst_offset) { m_ssbo_length = (src_offset + src_length) - dst_offset; data_offset = dst_offset; } else { m_ssbo_length = (dst_offset - src_offset) + (src_length / sizeof(From)) * sizeof(To); data_offset = src_offset; } m_program.uniforms["data_length_in_bytes"] = src_length; m_program.uniforms["in_ptr"] = src_offset - data_offset; m_program.uniforms["out_ptr"] = dst_offset - data_offset; cs_shuffle_base::run(cmd, data, src_length, data_offset); } }; // Reverse morton-order block arrangement template <typename _BlockType, typename _BaseType, bool _SwapBytes> struct cs_deswizzle_3d final : compute_task { union params_t { u32 data[7]; struct { u32 width; u32 height; u32 depth; u32 logw; u32 logh; u32 logd; u32 mipmaps; }; } params; gl::buffer param_buffer; const gl::buffer* src_buffer = nullptr; const gl::buffer* dst_buffer = nullptr; u32 in_offset = 0; u32 out_offset = 0; u32 block_length = 0; cs_deswizzle_3d() { ensure((sizeof(_BlockType) & 3) == 0); // "Unsupported block type" initialize(); m_src = #include "../Program/GLSLSnippets/GPUDeswizzle.glsl" ; std::string transform; if constexpr (_SwapBytes) { if constexpr (sizeof(_BaseType) == 4) { transform = "bswap_u32"; } else if constexpr (sizeof(_BaseType) == 2) { transform = "bswap_u16"; } else { fmt::throw_exception("Unreachable"); } } const std::pair<std::string_view, std::string> syntax_replace[] = { { "%set, ", ""}, { "%loc", std::to_string(GL_COMPUTE_BUFFER_SLOT(0))}, { "%push_block", fmt::format("binding=%d, std140", GL_COMPUTE_BUFFER_SLOT(2)) }, { "%ws", std::to_string(optimal_group_size) }, { "%_wordcount", std::to_string(sizeof(_BlockType) / 4) }, { "%f", transform } }; m_src = fmt::replace_all(m_src, syntax_replace); param_buffer.create(gl::buffer::target::uniform, 32, nullptr, gl::buffer::memory_type::local, gl::buffer::usage::dynamic_update); } ~cs_deswizzle_3d() { param_buffer.remove(); } void bind_resources() override { src_buffer->bind_range(gl::buffer::target::ssbo, GL_COMPUTE_BUFFER_SLOT(0), in_offset, block_length); dst_buffer->bind_range(gl::buffer::target::ssbo, GL_COMPUTE_BUFFER_SLOT(1), out_offset, block_length); param_buffer.bind_range(gl::buffer::target::uniform, GL_COMPUTE_BUFFER_SLOT(2), 0, sizeof(params)); } void set_parameters(gl::command_context& /*cmd*/) { param_buffer.sub_data(0, sizeof(params), params.data); } void run(gl::command_context& cmd, const gl::buffer* dst, u32 out_offset, const gl::buffer* src, u32 in_offset, u32 data_length, u32 width, u32 height, u32 depth, u32 mipmaps) { dst_buffer = dst; src_buffer = src; this->in_offset = in_offset; this->out_offset = out_offset; this->block_length = data_length; params.width = width; params.height = height; params.depth = depth; params.mipmaps = mipmaps; params.logw = rsx::ceil_log2(width); params.logh = rsx::ceil_log2(height); params.logd = rsx::ceil_log2(depth); set_parameters(cmd); const u32 num_bytes_per_invocation = (sizeof(_BlockType) * optimal_group_size); const u32 linear_invocations = utils::aligned_div(data_length, num_bytes_per_invocation); compute_task::run(cmd, linear_invocations); } }; struct pixel_buffer_layout; class cs_image_to_ssbo : public compute_task { protected: gl::sampler_state m_sampler; public: void destroy() override { m_sampler.remove(); compute_task::destroy(); } virtual void run(gl::command_context& cmd, gl::viewable_image* src, const gl::buffer* dst, u32 out_offset, const coordu& region, const gl::pixel_buffer_layout& layout) = 0; }; struct cs_d24x8_to_ssbo final : cs_image_to_ssbo { cs_d24x8_to_ssbo(); void run(gl::command_context& cmd, gl::viewable_image* src, const gl::buffer* dst, u32 out_offset, const coordu& region, const gl::pixel_buffer_layout& layout) override; }; struct cs_rgba8_to_ssbo final : cs_image_to_ssbo { cs_rgba8_to_ssbo(); void run(gl::command_context& cmd, gl::viewable_image* src, const gl::buffer* dst, u32 out_offset, const coordu& region, const gl::pixel_buffer_layout& layout) override; }; struct cs_ssbo_to_color_image final : compute_task { cs_ssbo_to_color_image(); void run(gl::command_context& cmd, const buffer* src, const texture_view* dst, const u32 src_offset, const coordu& dst_region, const pixel_buffer_layout& layout); void run(gl::command_context& cmd, const buffer* src, texture* dst, const u32 src_offset, const coordu& dst_region, const pixel_buffer_layout& layout); }; // TODO: Replace with a proper manager extern std::unordered_map<u32, std::unique_ptr<gl::compute_task>> g_compute_tasks; template<class T> T* get_compute_task() { u32 index = id_manager::typeinfo::get_index<T>(); auto &e = g_compute_tasks[index]; if (!e) { e = std::make_unique<T>(); e->create(); } return static_cast<T*>(e.get()); } void destroy_compute_tasks(); }
10,131
C++
.h
322
27.639752
177
0.656256
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,136
GLVertexProgram.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLVertexProgram.h
#pragma once #include "../Program/VertexProgramDecompiler.h" #include "GLHelpers.h" #include "glutils/program.h" #include <unordered_map> enum { GL_VP_FORCE_ATTRIB_SCALING = 1, //Scale vertex read result GL_VP_ATTRIB_S16_INT = (1 << 1), //Attrib is a signed 16-bit integer GL_VP_ATTRIB_S32_INT = (1 << 2), //Attrib is a signed 32-bit integer GL_VP_SINT_MASK = (GL_VP_ATTRIB_S16_INT|GL_VP_ATTRIB_S32_INT) }; namespace gl { class shader_interpreter; }; struct GLVertexDecompilerThread : public VertexProgramDecompiler { friend class gl::shader_interpreter; std::string &m_shader; protected: std::string getFloatTypeName(usz elementCount) override; std::string getIntTypeName(usz elementCount) override; std::string getFunction(FUNCTION) override; std::string compareFunction(COMPARE, const std::string&, const std::string&, bool scalar) override; void insertHeader(std::stringstream &OS) override; void insertInputs(std::stringstream &OS, const std::vector<ParamType> &inputs) override; void insertConstants(std::stringstream &OS, const std::vector<ParamType> &constants) override; void insertOutputs(std::stringstream &OS, const std::vector<ParamType> &outputs) override; void insertMainStart(std::stringstream &OS) override; void insertMainEnd(std::stringstream &OS) override; const RSXVertexProgram &rsx_vertex_program; std::unordered_map<std::string, int> input_locations; public: GLVertexDecompilerThread(const RSXVertexProgram &prog, std::string& shader, ParamArray&) : VertexProgramDecompiler(prog) , m_shader(shader) , rsx_vertex_program(prog) { } void Task(); }; class GLVertexProgram : public rsx::VertexProgramBase { public: GLVertexProgram(); ~GLVertexProgram(); ParamArray parr; gl::glsl::shader shader; void Decompile(const RSXVertexProgram& prog); private: void Delete(); };
1,836
C++
.h
53
32.735849
100
0.780791
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,137
GLShaderInterpreter.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLShaderInterpreter.h
#pragma once #include "GLHelpers.h" #include "glutils/program.h" #include "../Program/ProgramStateCache.h" #include "../Common/TextureUtils.h" #include <unordered_map> namespace gl { using namespace ::glsl; namespace interpreter { using program_metadata = program_hash_util::fragment_program_utils::fragment_program_metadata; enum class texture_pool_flags { dirty = 1 }; struct texture_pool { int pool_size = 0; int num_used = 0; u32 flags = 0; std::vector<int> allocated; bool allocate(int value) { if (num_used >= pool_size) { return false; } if (allocated.size() == unsigned(num_used)) { allocated.push_back(value); } else { allocated[num_used] = value; } num_used++; flags |= static_cast<u32>(texture_pool_flags::dirty); return true; } }; struct texture_pool_allocator { int max_image_units = 0; int used = 0; std::vector<texture_pool> pools; void create(::glsl::program_domain domain); void allocate(int size); }; struct cached_program { glsl::shader fs; glsl::program prog; texture_pool_allocator allocator; }; } class shader_interpreter { glsl::shader m_vs; std::unordered_map<u64, std::unique_ptr<interpreter::cached_program>> m_program_cache; void build_vs(); void build_fs(u64 compiler_options, interpreter::cached_program& prog_data); interpreter::cached_program* build_program(u64 compiler_options); interpreter::cached_program* m_current_interpreter = nullptr; public: void create(); void destroy(); void update_fragment_textures(const std::array<std::unique_ptr<rsx::sampled_image_descriptor_base>, 16>& descriptors, u16 reference_mask, u32* out); glsl::program* get(const interpreter::program_metadata& fp_metadata); bool is_interpreter(const glsl::program* program); }; }
1,872
C++
.h
72
22.444444
150
0.702748
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,138
GLProcTable.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLProcTable.h
OPENGL_PROC(PFNGLGENBUFFERSPROC, GenBuffers); OPENGL_PROC(PFNGLDELETEBUFFERSPROC, DeleteBuffers); OPENGL_PROC(PFNGLBINDBUFFERPROC, BindBuffer); OPENGL_PROC(PFNGLISBUFFERPROC, IsBuffer); OPENGL_PROC(PFNGLBUFFERDATAPROC, BufferData); OPENGL_PROC(PFNGLBUFFERSUBDATAPROC, BufferSubData); OPENGL_PROC(PFNGLGETBUFFERSUBDATAPROC, GetBufferSubData); OPENGL_PROC(PFNGLGETBUFFERPARAMETERIVPROC, GetBufferParameteriv); OPENGL_PROC(PFNGLGETBUFFERPOINTERVPROC, GetBufferPointerv); OPENGL_PROC(PFNGLBLENDFUNCSEPARATEPROC, BlendFuncSeparate); OPENGL_PROC(PFNGLBLENDEQUATIONSEPARATEPROC, BlendEquationSeparate); OPENGL_PROC(PFNGLCREATESHADERPROC, CreateShader); OPENGL_PROC(PFNGLDELETESHADERPROC, DeleteShader); OPENGL_PROC(PFNGLCOMPILESHADERPROC, CompileShader); OPENGL_PROC(PFNGLSHADERSOURCEPROC, ShaderSource); OPENGL_PROC(PFNGLGETSHADERIVPROC, GetShaderiv); OPENGL_PROC(PFNGLGETSHADERINFOLOGPROC, GetShaderInfoLog); OPENGL_PROC(PFNGLCREATEPROGRAMPROC, CreateProgram); OPENGL_PROC(PFNGLDELETEPROGRAMPROC, DeleteProgram); OPENGL_PROC(PFNGLATTACHSHADERPROC, AttachShader); OPENGL_PROC(PFNGLDETACHSHADERPROC, DetachShader); OPENGL_PROC(PFNGLGETATTRIBLOCATIONPROC, GetAttribLocation); OPENGL_PROC(PFNGLLINKPROGRAMPROC, LinkProgram); OPENGL_PROC(PFNGLVALIDATEPROGRAMPROC, ValidateProgram); OPENGL_PROC(PFNGLBINDFRAGDATALOCATIONPROC, BindFragDataLocation); OPENGL_PROC(PFNGLBINDATTRIBLOCATIONPROC, BindAttribLocation); OPENGL_PROC(PFNGLGETUNIFORMLOCATIONPROC, GetUniformLocation); OPENGL_PROC(PFNGLGETPROGRAMIVPROC, GetProgramiv); OPENGL_PROC(PFNGLGETPROGRAMINFOLOGPROC, GetProgramInfoLog); OPENGL_PROC(PFNGLVERTEXATTRIBPOINTERPROC, VertexAttribPointer); OPENGL_PROC(PFNGLENABLEVERTEXATTRIBARRAYPROC, EnableVertexAttribArray); OPENGL_PROC(PFNGLDISABLEVERTEXATTRIBARRAYPROC, DisableVertexAttribArray); OPENGL_PROC(PFNGLGENVERTEXARRAYSPROC, GenVertexArrays); OPENGL_PROC(PFNGLBINDVERTEXARRAYPROC, BindVertexArray); OPENGL_PROC(PFNGLDELETEVERTEXARRAYSPROC, DeleteVertexArrays); OPENGL_PROC(PFNGLDEPTHRANGEFPROC, DepthRangef); OPENGL_PROC(PFNGLTEXIMAGE3DPROC, TexImage3D); OPENGL_PROC(PFNGLTEXSUBIMAGE3DPROC, TexSubImage3D); OPENGL_PROC(PFNGLVERTEXATTRIB1FPROC, VertexAttrib1f); OPENGL_PROC(PFNGLVERTEXATTRIB1DPROC, VertexAttrib1d); OPENGL_PROC(PFNGLVERTEXATTRIB1FVPROC, VertexAttrib1fv); OPENGL_PROC(PFNGLVERTEXATTRIB1DVPROC, VertexAttrib1dv); OPENGL_PROC(PFNGLVERTEXATTRIB2FPROC, VertexAttrib2f); OPENGL_PROC(PFNGLVERTEXATTRIB2DPROC, VertexAttrib2d); OPENGL_PROC(PFNGLVERTEXATTRIB2FVPROC, VertexAttrib2fv); OPENGL_PROC(PFNGLVERTEXATTRIB2DVPROC, VertexAttrib2dv); OPENGL_PROC(PFNGLVERTEXATTRIB3FPROC, VertexAttrib3f); OPENGL_PROC(PFNGLVERTEXATTRIB3DPROC, VertexAttrib3d); OPENGL_PROC(PFNGLVERTEXATTRIB3FVPROC, VertexAttrib3fv); OPENGL_PROC(PFNGLVERTEXATTRIB3DVPROC, VertexAttrib3dv); OPENGL_PROC(PFNGLVERTEXATTRIB4FPROC, VertexAttrib4f); OPENGL_PROC(PFNGLVERTEXATTRIB4DPROC, VertexAttrib4d); OPENGL_PROC(PFNGLVERTEXATTRIB4IVPROC, VertexAttrib4iv); OPENGL_PROC(PFNGLVERTEXATTRIB4FVPROC, VertexAttrib4fv); OPENGL_PROC(PFNGLVERTEXATTRIB4DVPROC, VertexAttrib4dv); OPENGL_PROC(PFNGLVERTEXATTRIB4UIVPROC, VertexAttrib4uiv); OPENGL_PROC(PFNGLUNIFORM1IPROC, Uniform1i); OPENGL_PROC(PFNGLUNIFORM1FPROC, Uniform1f); OPENGL_PROC(PFNGLUNIFORM1DPROC, Uniform1d); OPENGL_PROC(PFNGLUNIFORM1UIPROC, Uniform1ui); OPENGL_PROC(PFNGLUNIFORM1IVPROC, Uniform1iv); OPENGL_PROC(PFNGLUNIFORM1FVPROC, Uniform1fv); OPENGL_PROC(PFNGLUNIFORM1DVPROC, Uniform1dv); OPENGL_PROC(PFNGLUNIFORM1UIVPROC, Uniform1uiv); OPENGL_PROC(PFNGLUNIFORM2IPROC, Uniform2i); OPENGL_PROC(PFNGLUNIFORM2FPROC, Uniform2f); OPENGL_PROC(PFNGLUNIFORM2DPROC, Uniform2d); OPENGL_PROC(PFNGLUNIFORM2UIPROC, Uniform2ui); OPENGL_PROC(PFNGLUNIFORM2IVPROC, Uniform2iv); OPENGL_PROC(PFNGLUNIFORM2FVPROC, Uniform2fv); OPENGL_PROC(PFNGLUNIFORM2DVPROC, Uniform2dv); OPENGL_PROC(PFNGLUNIFORM2UIVPROC, Uniform2uiv); OPENGL_PROC(PFNGLUNIFORM3IPROC, Uniform3i); OPENGL_PROC(PFNGLUNIFORM3FPROC, Uniform3f); OPENGL_PROC(PFNGLUNIFORM3DPROC, Uniform3d); OPENGL_PROC(PFNGLUNIFORM3UIPROC, Uniform3ui); OPENGL_PROC(PFNGLUNIFORM3IVPROC, Uniform3iv); OPENGL_PROC(PFNGLUNIFORM3FVPROC, Uniform3fv); OPENGL_PROC(PFNGLUNIFORM3DVPROC, Uniform3dv); OPENGL_PROC(PFNGLUNIFORM3UIVPROC, Uniform3uiv); OPENGL_PROC(PFNGLUNIFORM4IPROC, Uniform4i); OPENGL_PROC(PFNGLUNIFORM4FPROC, Uniform4f); OPENGL_PROC(PFNGLUNIFORM4DPROC, Uniform4d); OPENGL_PROC(PFNGLUNIFORM4UIPROC, Uniform4ui); OPENGL_PROC(PFNGLUNIFORM4IVPROC, Uniform4iv); OPENGL_PROC(PFNGLUNIFORM4FVPROC, Uniform4fv); OPENGL_PROC(PFNGLUNIFORM4DVPROC, Uniform4dv); OPENGL_PROC(PFNGLUNIFORM4UIVPROC, Uniform4uiv); OPENGL_PROC(PFNGLUNIFORMMATRIX2FVPROC, UniformMatrix2fv); OPENGL_PROC(PFNGLUNIFORMMATRIX2DVPROC, UniformMatrix2dv); OPENGL_PROC(PFNGLUNIFORMMATRIX3FVPROC, UniformMatrix3fv); OPENGL_PROC(PFNGLUNIFORMMATRIX3DVPROC, UniformMatrix3dv); OPENGL_PROC(PFNGLUNIFORMMATRIX4FVPROC, UniformMatrix4fv); OPENGL_PROC(PFNGLUNIFORMMATRIX4DVPROC, UniformMatrix4dv); OPENGL_PROC(PFNGLPROGRAMUNIFORM1IPROC, ProgramUniform1i); OPENGL_PROC(PFNGLPROGRAMUNIFORM1FPROC, ProgramUniform1f); OPENGL_PROC(PFNGLPROGRAMUNIFORM1DPROC, ProgramUniform1d); OPENGL_PROC(PFNGLPROGRAMUNIFORM1UIPROC, ProgramUniform1ui); OPENGL_PROC(PFNGLPROGRAMUNIFORM1IVPROC, ProgramUniform1iv); OPENGL_PROC(PFNGLPROGRAMUNIFORM1FVPROC, ProgramUniform1fv); OPENGL_PROC(PFNGLPROGRAMUNIFORM1DVPROC, ProgramUniform1dv); OPENGL_PROC(PFNGLPROGRAMUNIFORM1UIVPROC, ProgramUniform1uiv); OPENGL_PROC(PFNGLPROGRAMUNIFORM2IPROC, ProgramUniform2i); OPENGL_PROC(PFNGLPROGRAMUNIFORM2FPROC, ProgramUniform2f); OPENGL_PROC(PFNGLPROGRAMUNIFORM2DPROC, ProgramUniform2d); OPENGL_PROC(PFNGLPROGRAMUNIFORM2UIPROC, ProgramUniform2ui); OPENGL_PROC(PFNGLPROGRAMUNIFORM2IVPROC, ProgramUniform2iv); OPENGL_PROC(PFNGLPROGRAMUNIFORM2FVPROC, ProgramUniform2fv); OPENGL_PROC(PFNGLPROGRAMUNIFORM2DVPROC, ProgramUniform2dv); OPENGL_PROC(PFNGLPROGRAMUNIFORM2UIVPROC, ProgramUniform2uiv); OPENGL_PROC(PFNGLPROGRAMUNIFORM3IPROC, ProgramUniform3i); OPENGL_PROC(PFNGLPROGRAMUNIFORM3FPROC, ProgramUniform3f); OPENGL_PROC(PFNGLPROGRAMUNIFORM3DPROC, ProgramUniform3d); OPENGL_PROC(PFNGLPROGRAMUNIFORM3UIPROC, ProgramUniform3ui); OPENGL_PROC(PFNGLPROGRAMUNIFORM3IVPROC, ProgramUniform3iv); OPENGL_PROC(PFNGLPROGRAMUNIFORM3FVPROC, ProgramUniform3fv); OPENGL_PROC(PFNGLPROGRAMUNIFORM3DVPROC, ProgramUniform3dv); OPENGL_PROC(PFNGLPROGRAMUNIFORM3UIVPROC, ProgramUniform3uiv); OPENGL_PROC(PFNGLPROGRAMUNIFORM4IPROC, ProgramUniform4i); OPENGL_PROC(PFNGLPROGRAMUNIFORM4FPROC, ProgramUniform4f); OPENGL_PROC(PFNGLPROGRAMUNIFORM4DPROC, ProgramUniform4d); OPENGL_PROC(PFNGLPROGRAMUNIFORM4UIPROC, ProgramUniform4ui); OPENGL_PROC(PFNGLPROGRAMUNIFORM4IVPROC, ProgramUniform4iv); OPENGL_PROC(PFNGLPROGRAMUNIFORM4FVPROC, ProgramUniform4fv); OPENGL_PROC(PFNGLPROGRAMUNIFORM4DVPROC, ProgramUniform4dv); OPENGL_PROC(PFNGLPROGRAMUNIFORM4UIVPROC, ProgramUniform4uiv); OPENGL_PROC(PFNGLPROGRAMUNIFORMMATRIX2FVPROC, ProgramUniformMatrix2fv); OPENGL_PROC(PFNGLPROGRAMUNIFORMMATRIX2DVPROC, ProgramUniformMatrix2dv); OPENGL_PROC(PFNGLPROGRAMUNIFORMMATRIX3FVPROC, ProgramUniformMatrix3fv); OPENGL_PROC(PFNGLPROGRAMUNIFORMMATRIX3DVPROC, ProgramUniformMatrix3dv); OPENGL_PROC(PFNGLPROGRAMUNIFORMMATRIX4FVPROC, ProgramUniformMatrix4fv); OPENGL_PROC(PFNGLPROGRAMUNIFORMMATRIX4DVPROC, ProgramUniformMatrix4dv); OPENGL_PROC(PFNGLUSEPROGRAMPROC, UseProgram); OPENGL_PROC(PFNGLDEPTHBOUNDSEXTPROC, DepthBoundsEXT); OPENGL_PROC(PFNGLSTENCILOPSEPARATEPROC, StencilOpSeparate); OPENGL_PROC(PFNGLSTENCILFUNCSEPARATEPROC, StencilFuncSeparate); OPENGL_PROC(PFNGLSTENCILMASKSEPARATEPROC, StencilMaskSeparate); OPENGL_PROC(PFNGLGENERATEMIPMAPPROC, GenerateMipmap); OPENGL_PROC(PFNGLBINDRENDERBUFFERPROC, BindRenderbuffer); OPENGL_PROC(PFNGLDELETERENDERBUFFERSPROC, DeleteRenderbuffers); OPENGL_PROC(PFNGLGENRENDERBUFFERSPROC, GenRenderbuffers); OPENGL_PROC(PFNGLRENDERBUFFERSTORAGEPROC, RenderbufferStorage); OPENGL_PROC(PFNGLBINDFRAMEBUFFERPROC, BindFramebuffer); OPENGL_PROC(PFNGLDELETEFRAMEBUFFERSPROC, DeleteFramebuffers); OPENGL_PROC(PFNGLGENFRAMEBUFFERSPROC, GenFramebuffers); OPENGL_PROC(PFNGLBLITFRAMEBUFFERPROC, BlitFramebuffer); OPENGL_PROC(PFNGLNAMEDFRAMEBUFFERRENDERBUFFERPROC, NamedFramebufferRenderbuffer); OPENGL_PROC(PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC, NamedFramebufferRenderbufferEXT); OPENGL_PROC(PFNGLNAMEDFRAMEBUFFERTEXTUREPROC, NamedFramebufferTexture); OPENGL_PROC(PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC, NamedFramebufferTextureEXT); OPENGL_PROC(PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC, NamedFramebufferDrawBuffers); OPENGL_PROC(PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC, FramebufferDrawBuffersEXT); OPENGL_PROC(PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC, NamedFramebufferReadBuffer); OPENGL_PROC(PFNGLFRAMEBUFFERREADBUFFEREXTPROC, FramebufferReadBufferEXT); OPENGL_PROC(PFNGLENABLEIPROC, Enablei); OPENGL_PROC(PFNGLDISABLEIPROC, Disablei); OPENGL_PROC(PFNGLISENABLEDIPROC, IsEnabledi); OPENGL_PROC(PFNGLCOLORMASKIPROC, ColorMaski); OPENGL_PROC(PFNGLPRIMITIVERESTARTINDEXPROC, PrimitiveRestartIndex); OPENGL_PROC(PFNGLGETINTEGER64VPROC, GetInteger64v); OPENGL_PROC(PFNGLGETSTRINGIPROC, GetStringi); OPENGL_PROC(PFNGLGETINTEGERI_VPROC, GetIntegeri_v); OPENGL_PROC(PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC, CheckNamedFramebufferStatus); OPENGL_PROC(PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC, CheckNamedFramebufferStatusEXT); OPENGL_PROC(PFNGLBINDBUFFERRANGEPROC, BindBufferRange); OPENGL_PROC(PFNGLBINDBUFFERBASEPROC, BindBufferBase); OPENGL_PROC(PFNGLMAPNAMEDBUFFERRANGEPROC, MapNamedBufferRange); OPENGL_PROC(PFNGLMAPNAMEDBUFFERRANGEEXTPROC, MapNamedBufferRangeEXT); OPENGL_PROC(PFNGLUNMAPNAMEDBUFFERPROC, UnmapNamedBuffer); OPENGL_PROC(PFNGLUNMAPNAMEDBUFFEREXTPROC, UnmapNamedBufferEXT); OPENGL_PROC(PFNGLMULTIDRAWELEMENTSPROC, MultiDrawElements); OPENGL_PROC(PFNGLMULTIDRAWARRAYSPROC, MultiDrawArrays); OPENGL_PROC(PFNGLGETTEXTUREIMAGEEXTPROC, GetTextureImageEXT); OPENGL_PROC(PFNGLGETTEXTUREIMAGEPROC, GetTextureImage); OPENGL_PROC(PFNGLGETTEXTURESUBIMAGEPROC, GetTextureSubImage); OPENGL_PROC(PFNGLTEXTURESUBIMAGE1DEXTPROC, TextureSubImage1DEXT); OPENGL_PROC(PFNGLTEXTURESUBIMAGE1DPROC, TextureSubImage1D); OPENGL_PROC(PFNGLTEXTURESUBIMAGE2DEXTPROC, TextureSubImage2DEXT); OPENGL_PROC(PFNGLTEXTURESUBIMAGE2DPROC, TextureSubImage2D); OPENGL_PROC(PFNGLTEXTURESUBIMAGE3DEXTPROC, TextureSubImage3DEXT); OPENGL_PROC(PFNGLTEXTURESUBIMAGE3DPROC, TextureSubImage3D); OPENGL_PROC(PFNGLCOMPRESSEDTEXTURESUBIMAGE1DPROC, CompressedTextureSubImage1D); OPENGL_PROC(PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC, CompressedTextureSubImage1DEXT); OPENGL_PROC(PFNGLCOMPRESSEDTEXTURESUBIMAGE2DPROC, CompressedTextureSubImage2D); OPENGL_PROC(PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC, CompressedTextureSubImage2DEXT); OPENGL_PROC(PFNGLCOMPRESSEDTEXTURESUBIMAGE3DPROC, CompressedTextureSubImage3D); OPENGL_PROC(PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC, CompressedTextureSubImage3DEXT); OPENGL_PROC(PFNGLTEXTUREPARAMETERIPROC, TextureParameteri); OPENGL_PROC(PFNGLTEXTUREPARAMETERIEXTPROC, TextureParameteriEXT); OPENGL_PROC(PFNGLTEXTUREPARAMETERIVPROC, TextureParameteriv); OPENGL_PROC(PFNGLTEXTUREPARAMETERIVEXTPROC, TextureParameterivEXT); OPENGL_PROC(PFNGLCLEARBUFFERFVPROC, ClearBufferfv); OPENGL_PROC(PFNGLCOPYNAMEDBUFFERSUBDATAPROC, CopyNamedBufferSubData); OPENGL_PROC(PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC, NamedCopyBufferSubDataEXT); OPENGL_PROC(PFNGLNAMEDBUFFERDATAPROC, NamedBufferData); OPENGL_PROC(PFNGLNAMEDBUFFERDATAEXTPROC, NamedBufferDataEXT); OPENGL_PROC(PFNGLNAMEDBUFFERSUBDATAPROC, NamedBufferSubData); OPENGL_PROC(PFNGLNAMEDBUFFERSUBDATAEXTPROC, NamedBufferSubDataEXT); // ARB_shader_image_load_store OPENGL_PROC(PFNGLBINDIMAGETEXTUREPROC, BindImageTexture); // Sampler Objects OPENGL_PROC(PFNGLGENSAMPLERSPROC, GenSamplers); OPENGL_PROC(PFNGLDELETESAMPLERSPROC, DeleteSamplers); OPENGL_PROC(PFNGLBINDSAMPLERPROC, BindSampler); OPENGL_PROC(PFNGLSAMPLERPARAMETERIPROC, SamplerParameteri); OPENGL_PROC(PFNGLSAMPLERPARAMETERFPROC, SamplerParameterf); OPENGL_PROC(PFNGLSAMPLERPARAMETERFVPROC, SamplerParameterfv); // Occlusion Query OPENGL_PROC(PFNGLGENQUERIESPROC, GenQueries); OPENGL_PROC(PFNGLDELETEQUERIESPROC, DeleteQueries); OPENGL_PROC(PFNGLGETQUERYOBJECTIVPROC, GetQueryObjectiv); OPENGL_PROC(PFNGLBEGINQUERYPROC, BeginQuery); OPENGL_PROC(PFNGLENDQUERYPROC, EndQuery); // Texture Buffers OPENGL_PROC(PFNGLTEXTUREBUFFERRANGEEXTPROC, TextureBufferRangeEXT); OPENGL_PROC(PFNGLTEXTUREBUFFERRANGEPROC, TextureBufferRange); // ARB_Copy_Image OPENGL_PROC(PFNGLCOPYIMAGESUBDATAPROC, CopyImageSubData); // ARB_Buffer_Storage OPENGL_PROC(PFNGLNAMEDBUFFERSTORAGEPROC, NamedBufferStorage); OPENGL_PROC(PFNGLNAMEDBUFFERSTORAGEEXTPROC, NamedBufferStorageEXT); // ARB_sync OPENGL_PROC(PFNGLFENCESYNCPROC, FenceSync); OPENGL_PROC(PFNGLCLIENTWAITSYNCPROC, ClientWaitSync); OPENGL_PROC(PFNGLWAITSYNCPROC, WaitSync); OPENGL_PROC(PFNGLGETSYNCIVPROC, GetSynciv); OPENGL_PROC(PFNGLDELETESYNCPROC, DeleteSync); // KHR_debug OPENGL_PROC(PFNGLDEBUGMESSAGECALLBACKPROC, DebugMessageCallback); // Immutable textures OPENGL_PROC(PFNGLTEXSTORAGE1DPROC, TexStorage1D); OPENGL_PROC(PFNGLTEXSTORAGE2DPROC, TexStorage2D); OPENGL_PROC(PFNGLTEXSTORAGE3DPROC, TexStorage3D); // Texture_View OPENGL_PROC(PFNGLTEXTUREVIEWPROC, TextureView); // Texture_Barrier OPENGL_PROC(PFNGLTEXTUREBARRIERPROC, TextureBarrier); OPENGL_PROC(PFNGLTEXTUREBARRIERNVPROC, TextureBarrierNV); //... // Memory barrier OPENGL_PROC(PFNGLMEMORYBARRIERPROC, MemoryBarrier); // ARB_compute_shader OPENGL_PROC(PFNGLDISPATCHCOMPUTEPROC, DispatchCompute); // NV_depth_buffer_float OPENGL_PROC(PFNGLDEPTHRANGEDNVPROC, DepthRangedNV); OPENGL_PROC(PFNGLDEPTHBOUNDSDNVPROC, DepthBoundsdNV); // EXT_debug_marker OPENGL_PROC(PFNGLINSERTEVENTMARKEREXTPROC, InsertEventMarkerEXT); WGL_PROC(PFNWGLSWAPINTERVALEXTPROC, SwapIntervalEXT); #if !defined(__GNUG__) || defined(__MINGW32__) OPENGL_PROC(PFNGLBLENDCOLORPROC, BlendColor); OPENGL_PROC(PFNGLBLENDEQUATIONPROC, BlendEquation); OPENGL_PROC(PFNGLACTIVETEXTUREPROC, ActiveTexture); #endif
13,910
C++
.h
254
53.625984
87
0.888995
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,139
GLGSRender.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/GLGSRender.h
#pragma once #include "Emu/RSX/GSRender.h" #include "GLHelpers.h" #include "GLTexture.h" #include "GLTextureCache.h" #include "GLRenderTargets.h" #include "GLProgramBuffer.h" #include "GLOverlays.h" #include "GLShaderInterpreter.h" #include <optional> #include <unordered_map> #include "glutils/ring_buffer.h" #include "upscalers/upscaling.h" #ifdef _MSC_VER #pragma comment(lib, "opengl32.lib") #endif using namespace gl::upscaling_flags_; namespace gl { using vertex_cache = rsx::vertex_cache::default_vertex_cache<rsx::vertex_cache::uploaded_range>; using weak_vertex_cache = rsx::vertex_cache::weak_vertex_cache; using null_vertex_cache = vertex_cache; using shader_cache = rsx::shaders_cache<void*, GLProgramBuffer>; struct vertex_upload_info { u32 vertex_draw_count; u32 allocated_vertex_count; u32 first_vertex; u32 vertex_index_base; u32 vertex_index_offset; u32 persistent_mapping_offset; u32 volatile_mapping_offset; std::optional<std::tuple<GLenum, u32> > index_info; }; struct work_item { u32 address_to_flush = 0; gl::texture_cache::thrashed_set section_data; volatile bool processed = false; volatile bool result = false; volatile bool received = false; void producer_wait() { while (!processed) { std::this_thread::yield(); } received = true; } }; struct present_surface_info { u32 address; u32 format; u32 width; u32 height; u32 pitch; u8 eye; }; } class GLGSRender : public GSRender, public ::rsx::reports::ZCULL_control { gl::sampler_state m_fs_sampler_states[rsx::limits::fragment_textures_count]; // Fragment textures gl::sampler_state m_fs_sampler_mirror_states[rsx::limits::fragment_textures_count]; // Alternate views of fragment textures with different format (e.g Depth vs Stencil for D24S8) gl::sampler_state m_vs_sampler_states[rsx::limits::vertex_textures_count]; // Vertex textures gl::glsl::program *m_program = nullptr; const GLFragmentProgram *m_fragment_prog = nullptr; const GLVertexProgram *m_vertex_prog = nullptr; rsx::flags32_t m_interpreter_state = 0; gl::shader_interpreter m_shader_interpreter; gl_render_targets m_rtts; gl::texture_cache m_gl_texture_cache; gl::buffer_view m_persistent_stream_view; gl::buffer_view m_volatile_stream_view; std::unique_ptr<gl::texture> m_gl_persistent_stream_buffer; std::unique_ptr<gl::texture> m_gl_volatile_stream_buffer; std::unique_ptr<gl::ring_buffer> m_attrib_ring_buffer; std::unique_ptr<gl::ring_buffer> m_fragment_constants_buffer; std::unique_ptr<gl::ring_buffer> m_transform_constants_buffer; std::unique_ptr<gl::ring_buffer> m_fragment_env_buffer; std::unique_ptr<gl::ring_buffer> m_vertex_env_buffer; std::unique_ptr<gl::ring_buffer> m_texture_parameters_buffer; std::unique_ptr<gl::ring_buffer> m_vertex_layout_buffer; std::unique_ptr<gl::ring_buffer> m_index_ring_buffer; std::unique_ptr<gl::ring_buffer> m_vertex_instructions_buffer; std::unique_ptr<gl::ring_buffer> m_fragment_instructions_buffer; std::unique_ptr<gl::ring_buffer> m_raster_env_ring_buffer; // Identity buffer used to fix broken gl_VertexID on ATI stack std::unique_ptr<gl::buffer> m_identity_index_buffer; // Used for hot-patching std::unique_ptr<gl::ring_buffer> m_scratch_ring_buffer; std::unique_ptr<gl::vertex_cache> m_vertex_cache; std::unique_ptr<gl::shader_cache> m_shaders_cache; GLint m_min_texbuffer_alignment = 256; GLint m_uniform_buffer_offset_align = 256; GLint m_max_texbuffer_size = 65536; bool manually_flush_ring_buffers = false; gl::ui_overlay_renderer m_ui_renderer; gl::video_out_calibration_pass m_video_output_pass; shared_mutex queue_guard; std::list<gl::work_item> work_queue; GLProgramBuffer m_prog_buffer; // Draw Buffers gl::fbo* m_draw_fbo = nullptr; std::list<gl::framebuffer_holder> m_framebuffer_cache; std::unique_ptr<gl::texture> m_flip_tex_color[2]; // Present std::unique_ptr<gl::upscaler> m_upscaler; output_scaling_mode m_output_scaling = output_scaling_mode::bilinear; // VAOs are mandatory for core profile gl::vao m_vao; shared_mutex m_sampler_mutex; atomic_t<bool> m_samplers_dirty = {true}; std::array<std::unique_ptr<rsx::sampled_image_descriptor_base>, rsx::limits::fragment_textures_count> fs_sampler_state = {}; std::array<std::unique_ptr<rsx::sampled_image_descriptor_base>, rsx::limits::vertex_textures_count> vs_sampler_state = {}; std::unordered_map<GLenum, std::unique_ptr<gl::texture>> m_null_textures; rsx::simple_array<u8> m_scratch_buffer; // Occlusion query type, can be SAMPLES_PASSED or ANY_SAMPLES_PASSED GLenum m_occlusion_type = GL_ANY_SAMPLES_PASSED; // Host context for GPU-driven work std::unique_ptr<gl::buffer> m_host_gpu_context_data; std::unique_ptr<gl::scratch_ring_buffer> m_enqueued_host_write_buffer; public: u64 get_cycles() final; GLGSRender(utils::serial* ar) noexcept; GLGSRender() noexcept : GLGSRender(nullptr) {} private: gl::driver_state gl_state; // Return element to draw and in case of indexed draw index type and offset in index buffer gl::vertex_upload_info set_vertex_buffer(); rsx::vertex_input_layout m_vertex_layout = {}; void init_buffers(rsx::framebuffer_creation_context context, bool skip_reading = false); bool load_program(); void load_program_env(); void update_vertex_env(const gl::vertex_upload_info& upload_info); void upload_transform_constants(const rsx::io_buffer& buffer); void update_draw_state(); void load_texture_env(); void bind_texture_env(); gl::texture* get_present_source(gl::present_surface_info* info, const rsx::avconf& avconfig); public: void set_viewport(); void set_scissor(bool clip_viewport); gl::work_item& post_flush_request(u32 address, gl::texture_cache::thrashed_set& flush_data); bool scaled_image_from_memory(const rsx::blit_src_info& src_info, const rsx::blit_dst_info& dst_info, bool interpolate) override; // ZCULL void begin_occlusion_query(rsx::reports::occlusion_query_info* query) override; void end_occlusion_query(rsx::reports::occlusion_query_info* query) override; bool check_occlusion_query_status(rsx::reports::occlusion_query_info* query) override; void get_occlusion_query_result(rsx::reports::occlusion_query_info* query) override; void discard_occlusion_query(rsx::reports::occlusion_query_info* query) override; // DMA bool release_GCM_label(u32 address, u32 data) override; void enqueue_host_context_write(u32 offset, u32 size, const void* data); void on_guest_texture_read(); // GRAPH backend void patch_transform_constants(rsx::context* ctx, u32 index, u32 count) override; protected: void clear_surface(u32 arg) override; void begin() override; void end() override; void emit_geometry(u32 sub_index) override; void on_init_thread() override; void on_exit() override; void flip(const rsx::display_flip_info_t& info) override; void do_local_task(rsx::FIFO::state state) override; bool on_access_violation(u32 address, bool is_writing) override; void on_invalidate_memory_range(const utils::address_range &range, rsx::invalidation_cause cause) override; void notify_tile_unbound(u32 tile) override; void on_semaphore_acquire_wait() override; };
7,203
C++
.h
171
39.777778
180
0.759421
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,140
nearest_pass.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/upscalers/nearest_pass.hpp
#pragma once #include "static_pass.hpp" namespace gl { using nearest_upscale_pass = static_upscale_pass<gl::filter::nearest>; }
139
C++
.h
6
20.333333
72
0.744186
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,141
upscaling.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/upscalers/upscaling.h
#pragma once #include "util/types.hpp" #include "../glutils/fbo.h" #include "../glutils/image.h" #include "../glutils/state_tracker.hpp" namespace gl { namespace upscaling_flags_ { enum upscaling_flags { UPSCALE_DEFAULT_VIEW = (1 << 0), UPSCALE_LEFT_VIEW = (1 << 0), UPSCALE_RIGHT_VIEW = (1 << 1), UPSCALE_AND_COMMIT = (1 << 2) }; } using namespace upscaling_flags_; struct upscaler { virtual ~upscaler() {} virtual gl::texture* scale_output( gl::command_context& cmd, // State gl::texture* src, // Source input const areai& src_region, // Scaling request information const areai& dst_region, // Ditto gl::flags32_t mode // Mode ) = 0; }; }
816
C++
.h
30
23.266667
74
0.567183
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,142
static_pass.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/upscalers/static_pass.hpp
#pragma once #include "../glutils/fbo.h" #include "upscaling.h" namespace gl { template<gl::filter Filter> class static_upscale_pass : public upscaler { public: static_upscale_pass() = default; ~static_upscale_pass() { if (m_flip_fbo) { m_flip_fbo.remove(); } } gl::texture* scale_output( gl::command_context& /*cmd*/, // State gl::texture* src, // Source input const areai& src_region, // Scaling request information const areai& dst_region, // Ditto gl::flags32_t mode // Mode ) override { if (mode & UPSCALE_AND_COMMIT) { m_flip_fbo.recreate(); m_flip_fbo.bind(); m_flip_fbo.color = src->id(); m_flip_fbo.read_buffer(m_flip_fbo.color); m_flip_fbo.draw_buffer(m_flip_fbo.color); m_flip_fbo.blit(gl::screen, src_region, dst_region, gl::buffers::color, Filter); return nullptr; } // Upscaling source only is unsupported return src; } private: gl::fbo m_flip_fbo; }; }
1,100
C++
.h
42
21.642857
85
0.581262
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,143
fsr_pass.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/upscalers/fsr_pass.h
#pragma once #include "../glutils/buffer_object.h" #include "../glutils/state_tracker.hpp" #include "../GLCompute.h" #include "upscaling.h" namespace gl { namespace FidelityFX { class fsr_pass : public compute_task { protected: gl::texture* m_input_image = nullptr; gl::texture* m_output_image = nullptr; size2u m_input_size; size2u m_output_size; std::vector<u32> m_constants_buf; gl::sampler_state m_sampler; gl::buffer m_ubo; void bind_resources() override; virtual void configure() = 0; public: fsr_pass(const std::string& config_definitions, u32 push_constants_size); virtual ~fsr_pass(); void run(gl::command_context& cmd, gl::texture* src, gl::texture* dst, const size2u& input_size, const size2u& output_size); }; class easu_pass : public fsr_pass { void configure() override; public: easu_pass(); }; class rcas_pass : public fsr_pass { void configure() override; public: rcas_pass(); }; } class fsr_upscale_pass : public upscaler { public: fsr_upscale_pass() = default; ~fsr_upscale_pass(); gl::texture* scale_output( gl::command_context& cmd, // State gl::texture* src, // Source input const areai& src_region, // Scaling request information const areai& dst_region, // Ditto gl::flags32_t mode // Mode ) override; private: std::unique_ptr<gl::viewable_image> m_output_left; std::unique_ptr<gl::viewable_image> m_output_right; std::unique_ptr<gl::viewable_image> m_intermediate_data; gl::fbo m_flip_fbo; void dispose_images(); void initialize_image(u32 output_w, u32 output_h, rsx::flags32_t mode); }; }
1,810
C++
.h
60
25.683333
128
0.639697
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,144
bilinear_pass.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/upscalers/bilinear_pass.hpp
#pragma once #include "static_pass.hpp" namespace gl { using bilinear_upscale_pass = static_upscale_pass<gl::filter::linear>; }
139
C++
.h
6
20.333333
72
0.744186
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,145
pixel_settings.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/pixel_settings.hpp
#pragma once #include "common.h" namespace gl { class pixel_pack_settings { bool m_swap_bytes = false; bool m_lsb_first = false; int m_row_length = 0; int m_image_height = 0; int m_skip_rows = 0; int m_skip_pixels = 0; int m_skip_images = 0; int m_alignment = 4; public: void apply() const { glPixelStorei(GL_PACK_SWAP_BYTES, m_swap_bytes ? GL_TRUE : GL_FALSE); glPixelStorei(GL_PACK_LSB_FIRST, m_lsb_first ? GL_TRUE : GL_FALSE); glPixelStorei(GL_PACK_ROW_LENGTH, m_row_length); glPixelStorei(GL_PACK_IMAGE_HEIGHT, m_image_height); glPixelStorei(GL_PACK_SKIP_ROWS, m_skip_rows); glPixelStorei(GL_PACK_SKIP_PIXELS, m_skip_pixels); glPixelStorei(GL_PACK_SKIP_IMAGES, m_skip_images); glPixelStorei(GL_PACK_ALIGNMENT, m_alignment); } pixel_pack_settings& swap_bytes(bool value = true) { m_swap_bytes = value; return *this; } pixel_pack_settings& lsb_first(bool value = true) { m_lsb_first = value; return *this; } pixel_pack_settings& row_length(int value) { m_row_length = value; return *this; } pixel_pack_settings& image_height(int value) { m_image_height = value; return *this; } pixel_pack_settings& skip_rows(int value) { m_skip_rows = value; return *this; } pixel_pack_settings& skip_pixels(int value) { m_skip_pixels = value; return *this; } pixel_pack_settings& skip_images(int value) { m_skip_images = value; return *this; } pixel_pack_settings& alignment(int value) { m_alignment = value; return *this; } bool get_swap_bytes() const { return m_swap_bytes; } int get_row_length() const { return m_row_length; } }; class pixel_unpack_settings { bool m_swap_bytes = false; bool m_lsb_first = false; int m_row_length = 0; int m_image_height = 0; int m_skip_rows = 0; int m_skip_pixels = 0; int m_skip_images = 0; int m_alignment = 4; public: void apply() const { glPixelStorei(GL_UNPACK_SWAP_BYTES, m_swap_bytes ? GL_TRUE : GL_FALSE); glPixelStorei(GL_UNPACK_LSB_FIRST, m_lsb_first ? GL_TRUE : GL_FALSE); glPixelStorei(GL_UNPACK_ROW_LENGTH, m_row_length); glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, m_image_height); glPixelStorei(GL_UNPACK_SKIP_ROWS, m_skip_rows); glPixelStorei(GL_UNPACK_SKIP_PIXELS, m_skip_pixels); glPixelStorei(GL_UNPACK_SKIP_IMAGES, m_skip_images); glPixelStorei(GL_UNPACK_ALIGNMENT, m_alignment); } pixel_unpack_settings& swap_bytes(bool value = true) { m_swap_bytes = value; return *this; } pixel_unpack_settings& lsb_first(bool value = true) { m_lsb_first = value; return *this; } pixel_unpack_settings& row_length(int value) { m_row_length = value; return *this; } pixel_unpack_settings& image_height(int value) { m_image_height = value; return *this; } pixel_unpack_settings& skip_rows(int value) { m_skip_rows = value; return *this; } pixel_unpack_settings& skip_pixels(int value) { m_skip_pixels = value; return *this; } pixel_unpack_settings& skip_images(int value) { m_skip_images = value; return *this; } pixel_unpack_settings& alignment(int value) { m_alignment = value; return *this; } bool get_swap_bytes() const { return m_swap_bytes; } int get_row_length() const { return m_row_length; } }; }
3,523
C++
.h
147
19.598639
75
0.651669
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,146
fbo.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/fbo.h
#pragma once #include "common.h" #include "image.h" #include "pixel_settings.hpp" #include "Utilities/geometry.h" namespace gl { enum class buffers { none = 0, color = GL_COLOR_BUFFER_BIT, depth = GL_DEPTH_BUFFER_BIT, stencil = GL_STENCIL_BUFFER_BIT, color_depth = color | depth, color_depth_stencil = color | depth | stencil, color_stencil = color | stencil, depth_stencil = depth | stencil }; enum class indices_type { ubyte = GL_UNSIGNED_BYTE, ushort = GL_UNSIGNED_SHORT, uint = GL_UNSIGNED_INT }; class vao; class fbo { GLuint m_id = GL_NONE; size2i m_size; protected: std::unordered_map<GLenum, GLuint> m_resource_bindings; public: fbo() = default; fbo(GLuint id) { set_id(id); } ~fbo() { if (created()) remove(); } class save_binding_state { GLint m_last_binding; bool reset = true; public: save_binding_state(const fbo& new_binding) { glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_last_binding); if (m_last_binding + 0u != new_binding.id()) new_binding.bind(); else reset = false; } ~save_binding_state() { if (reset) glBindFramebuffer(GL_FRAMEBUFFER, m_last_binding); } }; class attachment { public: enum class type { color = GL_COLOR_ATTACHMENT0, depth = GL_DEPTH_ATTACHMENT, stencil = GL_STENCIL_ATTACHMENT, depth_stencil = GL_DEPTH_STENCIL_ATTACHMENT }; protected: GLuint m_id = GL_NONE; fbo& m_parent; attachment(fbo& parent) : m_parent(parent) {} public: attachment(fbo& parent, type type) : m_id(static_cast<int>(type)) , m_parent(parent) { } void set_id(uint id) { m_id = id; } uint id() const { return m_id; } GLuint resource_id() const { const auto found = m_parent.m_resource_bindings.find(m_id); if (found != m_parent.m_resource_bindings.end()) { return found->second; } return 0; } void operator = (const texture& rhs) { ensure(rhs.get_target() == texture::target::texture2D); m_parent.m_resource_bindings[m_id] = rhs.id(); DSA_CALL2(NamedFramebufferTexture, m_parent.id(), m_id, rhs.id(), 0); } void operator = (const GLuint rhs) { m_parent.m_resource_bindings[m_id] = rhs; DSA_CALL2(NamedFramebufferTexture, m_parent.id(), m_id, rhs, 0); } }; class indexed_attachment : public attachment { public: indexed_attachment(fbo& parent, type type) : attachment(parent, type) { } attachment operator[](int index) const { return{ m_parent, type(id() + index) }; } std::vector<attachment> range(int from, int count) const { std::vector<attachment> result; for (int i = from; i < from + count; ++i) result.push_back((*this)[i]); return result; } using attachment::operator =; }; struct null_attachment : public attachment { null_attachment(fbo& parent) : attachment(parent) {} }; indexed_attachment color{ *this, attachment::type::color }; attachment depth{ *this, attachment::type::depth }; attachment stencil{ *this, attachment::type::stencil }; attachment depth_stencil{ *this, attachment::type::depth_stencil }; null_attachment no_color{ *this }; enum class target { read_frame_buffer = GL_READ_FRAMEBUFFER, draw_frame_buffer = GL_DRAW_FRAMEBUFFER }; enum class swapchain_buffer { back = GL_BACK, front = GL_FRONT }; void create(); void bind() const; void blit(const fbo& dst, areai src_area, areai dst_area, buffers buffers_ = buffers::color, filter filter_ = filter::nearest) const; void bind_as(target target_) const; void remove(); bool created() const; bool check() const; void recreate(); void draw_buffer(const attachment& buffer) const; void draw_buffer(swapchain_buffer buffer) const; void draw_buffers(const std::initializer_list<attachment>& indexes) const; void read_buffer(const attachment& buffer) const; void read_buffer(swapchain_buffer buffer) const; void draw_arrays(GLenum mode, GLsizei count, GLint first = 0) const; void draw_arrays(const buffer& buffer, GLenum mode, GLsizei count, GLint first = 0) const; void draw_arrays(const vao& buffer, GLenum mode, GLsizei count, GLint first = 0) const; void draw_elements(GLenum mode, GLsizei count, indices_type type, const GLvoid* indices) const; void draw_elements(const buffer& buffer, GLenum mode, GLsizei count, indices_type type, const GLvoid* indices) const; void draw_elements(GLenum mode, GLsizei count, indices_type type, const buffer& indices, usz indices_buffer_offset = 0) const; void draw_elements(const buffer& buffer_, GLenum mode, GLsizei count, indices_type type, const buffer& indices, usz indices_buffer_offset = 0) const; void draw_elements(GLenum mode, GLsizei count, const GLubyte* indices) const; void draw_elements(const buffer& buffer, GLenum mode, GLsizei count, const GLubyte* indices) const; void draw_elements(GLenum mode, GLsizei count, const GLushort* indices) const; void draw_elements(const buffer& buffer, GLenum mode, GLsizei count, const GLushort* indices) const; void draw_elements(GLenum mode, GLsizei count, const GLuint* indices) const; void draw_elements(const buffer& buffer, GLenum mode, GLsizei count, const GLuint* indices) const; void clear(buffers buffers_) const; void copy_from(const void* pixels, const sizei& size, gl::texture::format format_, gl::texture::type type_, class pixel_unpack_settings pixel_settings = pixel_unpack_settings()) const; void copy_from(const buffer& buf, const sizei& size, gl::texture::format format_, gl::texture::type type_, class pixel_unpack_settings pixel_settings = pixel_unpack_settings()) const; void copy_to(void* pixels, coordi coord, gl::texture::format format_, gl::texture::type type_, class pixel_pack_settings pixel_settings = pixel_pack_settings()) const; void copy_to(const buffer& buf, coordi coord, gl::texture::format format_, gl::texture::type type_, class pixel_pack_settings pixel_settings = pixel_pack_settings()) const; static fbo get_bound_draw_buffer(); static fbo get_bound_read_buffer(); static fbo get_bound_buffer(); GLuint id() const; void set_id(GLuint id); void set_extents(const size2i& extents); size2i get_extents() const; bool matches(const std::array<GLuint, 4>& color_targets, GLuint depth_stencil_target) const; bool references_any(const std::vector<GLuint>& resources) const; explicit operator bool() const { return created(); } }; extern const fbo screen; }
6,846
C++
.h
199
29.417085
187
0.683366
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,147
program.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/program.h
#pragma once #include "common.h" #include "sync.hpp" #include "Emu/RSX/Program/GLSLTypes.h" #include "Utilities/geometry.h" #include "Utilities/mutex.h" namespace gl { namespace glsl { class shader { std::string source; ::glsl::program_domain type; GLuint m_id = GL_NONE; fence m_compiled_fence; fence m_init_fence; shared_mutex m_compile_lock; atomic_t<bool> m_is_compiled{}; void precompile(); public: shader() = default; shader(::glsl::program_domain type_, const std::string& src) { create(type_, src); } ~shader() { remove(); } void remove() { if (m_id) { glDeleteShader(m_id); m_id = GL_NONE; } } void create(::glsl::program_domain type_, const std::string& src); shader& compile(); uint id() const { return m_id; } const std::string& get_source() const { return source; } fence get_compile_fence_sync() const { return m_compiled_fence; } bool created() const { return m_id != GL_NONE; } bool compiled() const { return m_is_compiled; } explicit operator bool() const { return created(); } }; class program { GLuint m_id = GL_NONE; fence m_fence; public: class uniform_t { program& m_program; GLint m_location; public: uniform_t(program& program, GLint location) : m_program(program) , m_location(location) { } GLint location() const { return m_location; } void operator = (int rhs) const { glProgramUniform1i(m_program.id(), location(), rhs); } void operator = (unsigned rhs) const { glProgramUniform1ui(m_program.id(), location(), rhs); } void operator = (float rhs) const { glProgramUniform1f(m_program.id(), location(), rhs); } void operator = (bool rhs) const { glProgramUniform1ui(m_program.id(), location(), rhs ? 1 : 0); } void operator = (const color1i& rhs) const { glProgramUniform1i(m_program.id(), location(), rhs.r); } void operator = (const color1f& rhs) const { glProgramUniform1f(m_program.id(), location(), rhs.r); } void operator = (const color2i& rhs) const { glProgramUniform2i(m_program.id(), location(), rhs.r, rhs.g); } void operator = (const color2f& rhs) const { glProgramUniform2f(m_program.id(), location(), rhs.r, rhs.g); } void operator = (const color3i& rhs) const { glProgramUniform3i(m_program.id(), location(), rhs.r, rhs.g, rhs.b); } void operator = (const color3f& rhs) const { glProgramUniform3f(m_program.id(), location(), rhs.r, rhs.g, rhs.b); } void operator = (const color4i& rhs) const { glProgramUniform4i(m_program.id(), location(), rhs.r, rhs.g, rhs.b, rhs.a); } void operator = (const color4f& rhs) const { glProgramUniform4f(m_program.id(), location(), rhs.r, rhs.g, rhs.b, rhs.a); } void operator = (const areaf& rhs) const { glProgramUniform4f(m_program.id(), location(), rhs.x1, rhs.y1, rhs.x2, rhs.y2); } void operator = (const areai& rhs) const { glProgramUniform4i(m_program.id(), location(), rhs.x1, rhs.y1, rhs.x2, rhs.y2); } void operator = (const std::vector<int>& rhs) const { glProgramUniform1iv(m_program.id(), location(), ::size32(rhs), rhs.data()); } }; class uniforms_t { program& m_program; std::unordered_map<std::string, GLint> locations; public: uniforms_t(program* program) : m_program(*program) {} void clear() { locations.clear(); } bool has_location(const std::string& name, int* location = nullptr); GLint location(const std::string& name); uniform_t operator[](GLint location) { return{ m_program, location }; } uniform_t operator[](const std::string& name) { return{ m_program, location(name) }; } } uniforms{ this }; public: program() = default; program(const program&) = delete; ~program() { if (created()) { remove(); } } program& recreate() { remove(); return create(); } program& create() { m_id = glCreateProgram(); return *this; } void remove() { glDeleteProgram(m_id); m_id = GL_NONE; uniforms.clear(); } void link(std::function<void(program*)> init_func = {}); void validate(); void sync() { if (!m_fence.check_signaled()) { m_fence.server_wait_sync(); } } program& attach(const shader& shader_) { glAttachShader(m_id, shader_.id()); return *this; } program& bind_attribute_location(const std::string& name, int index) { glBindAttribLocation(m_id, index, name.c_str()); return *this; } program& bind_fragment_data_location(const std::string& name, int color_number) { glBindFragDataLocation(m_id, color_number, name.c_str()); return *this; } GLuint id() const { return m_id; } bool created() const { return m_id != GL_NONE; } explicit operator bool() const { return created(); } }; } }
5,102
C++
.h
152
27.776316
136
0.624691
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,148
sampler.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/sampler.h
#pragma once #include "common.h" namespace rsx { class fragment_texture; class vertex_texture; class sampled_image_descriptor_base; } namespace gl { class sampler_state { GLuint sampler_handle = 0; std::unordered_map<GLenum, GLuint> m_propertiesi; std::unordered_map<GLenum, GLfloat> m_propertiesf; public: void create() { glGenSamplers(1, &sampler_handle); } void remove() { if (sampler_handle) { glDeleteSamplers(1, &sampler_handle); } } void bind(int index) const { glBindSampler(index, sampler_handle); } void set_parameteri(GLenum pname, GLuint value) { auto prop = m_propertiesi.find(pname); if (prop != m_propertiesi.end() && prop->second == value) { return; } m_propertiesi[pname] = value; glSamplerParameteri(sampler_handle, pname, value); } void set_parameterf(GLenum pname, GLfloat value) { auto prop = m_propertiesf.find(pname); if (prop != m_propertiesf.end() && prop->second == value) { return; } m_propertiesf[pname] = value; glSamplerParameterf(sampler_handle, pname, value); } GLuint get_parameteri(GLenum pname) { auto prop = m_propertiesi.find(pname); return (prop == m_propertiesi.end()) ? 0 : prop->second; } GLfloat get_parameterf(GLenum pname) { auto prop = m_propertiesf.find(pname); return (prop == m_propertiesf.end()) ? 0 : prop->second; } void apply(const rsx::fragment_texture& tex, const rsx::sampled_image_descriptor_base* sampled_image); void apply(const rsx::vertex_texture& tex, const rsx::sampled_image_descriptor_base* sampled_image); void apply_defaults(GLenum default_filter = GL_NEAREST); operator bool() const { return sampler_handle != GL_NONE; } }; struct saved_sampler_state { GLuint saved = GL_NONE; GLuint unit = 0; saved_sampler_state(GLuint _unit, const gl::sampler_state& sampler) { glActiveTexture(GL_TEXTURE0 + _unit); glGetIntegerv(GL_SAMPLER_BINDING, reinterpret_cast<GLint*>(&saved)); unit = _unit; sampler.bind(_unit); } saved_sampler_state(const saved_sampler_state&) = delete; ~saved_sampler_state() { glBindSampler(unit, saved); } }; }
2,303
C++
.h
86
22.174419
105
0.672644
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,149
vao.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/vao.hpp
#pragma once #include "common.h" #include "buffer_object.h" #include "Utilities/geometry.h" namespace gl { class vao; class buffer_pointer { public: enum class type { s8 = GL_BYTE, u8 = GL_UNSIGNED_BYTE, s16 = GL_SHORT, u16 = GL_UNSIGNED_SHORT, s32 = GL_INT, u32 = GL_UNSIGNED_INT, f16 = GL_HALF_FLOAT, f32 = GL_FLOAT, f64 = GL_DOUBLE, fixed = GL_FIXED, s32_2_10_10_10_rev = GL_INT_2_10_10_10_REV, u32_2_10_10_10_rev = GL_UNSIGNED_INT_2_10_10_10_REV, u32_10f_11f_11f_rev = GL_UNSIGNED_INT_10F_11F_11F_REV }; private: vao* m_vao; u32 m_offset; u32 m_stride; u32 m_size = 4; type m_type = type::f32; bool m_normalize = false; public: buffer_pointer(vao* vao, u32 offset = 0, u32 stride = 0) : m_vao(vao) , m_offset(offset) , m_stride(stride) { } const class ::gl::vao& get_vao() const { return *m_vao; } class ::gl::vao& get_vao() { return *m_vao; } buffer_pointer& offset(u32 value) { m_offset = value; return *this; } u32 offset() const { return m_offset; } buffer_pointer& stride(u32 value) { m_stride = value; return *this; } u32 stride() const { return m_stride; } buffer_pointer& size(u32 value) { m_size = value; return *this; } u32 size() const { return m_size; } buffer_pointer& set_type(type value) { m_type = value; return *this; } type get_type() const { return m_type; } buffer_pointer& normalize(bool value) { m_normalize = value; return *this; } bool normalize() const { return m_normalize; } buffer_pointer& operator >> (u32 value) { return stride(value); } buffer_pointer& config(type type_ = type::f32, u32 size_ = 4, bool normalize_ = false) { return set_type(type_).size(size_).normalize(normalize_); } }; class attrib_t; class vao { template<buffer::target BindId, uint GetStateId> class entry { vao& m_parent; public: using save_binding_state = save_binding_state_base<entry, (static_cast<GLuint>(BindId)), GetStateId>; entry(vao* parent) noexcept : m_parent(*parent) { } entry& operator = (const buffer& buf) noexcept { m_parent.bind(); buf.bind(BindId); return *this; } }; GLuint m_id = GL_NONE; public: entry<buffer::target::pixel_pack, GL_PIXEL_PACK_BUFFER_BINDING> pixel_pack_buffer{ this }; entry<buffer::target::pixel_unpack, GL_PIXEL_UNPACK_BUFFER_BINDING> pixel_unpack_buffer{ this }; entry<buffer::target::array, GL_ARRAY_BUFFER_BINDING> array_buffer{ this }; entry<buffer::target::element_array, GL_ELEMENT_ARRAY_BUFFER_BINDING> element_array_buffer{ this }; vao() = default; vao(const vao&) = delete; vao(vao&& vao_) noexcept { swap(vao_); } vao(GLuint id) noexcept { set_id(id); } ~vao() noexcept { if (created()) remove(); } void swap(vao& vao_) noexcept { auto my_old_id = id(); set_id(vao_.id()); vao_.set_id(my_old_id); } vao& operator = (const vao& rhs) = delete; vao& operator = (vao&& rhs) noexcept { swap(rhs); return *this; } void bind() const noexcept { glBindVertexArray(m_id); } void create() noexcept { glGenVertexArrays(1, &m_id); } void remove() noexcept { if (m_id != GL_NONE) { glDeleteVertexArrays(1, &m_id); m_id = GL_NONE; } } uint id() const noexcept { return m_id; } void set_id(uint id) noexcept { m_id = id; } bool created() const noexcept { return m_id != GL_NONE; } explicit operator bool() const noexcept { return created(); } void enable_for_attributes(std::initializer_list<GLuint> indexes) noexcept { for (auto& index : indexes) { glEnableVertexAttribArray(index); } } void disable_for_attributes(std::initializer_list<GLuint> indexes) noexcept { for (auto& index : indexes) { glDisableVertexAttribArray(index); } } void enable_for_attribute(GLuint index) noexcept { enable_for_attributes({ index }); } void disable_for_attribute(GLuint index) noexcept { disable_for_attributes({ index }); } buffer_pointer operator + (u32 offset) noexcept { return{ this, offset }; } buffer_pointer operator >> (u32 stride) noexcept { return{ this, {}, stride }; } operator buffer_pointer() noexcept { return{ this }; } attrib_t operator [] (u32 index) const noexcept; }; class attrib_t { GLint m_location; public: attrib_t(GLint location) : m_location(location) { } GLint location() const { return m_location; } void operator = (float rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib1f(location(), rhs); } void operator = (double rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib1d(location(), rhs); } void operator = (const color1f& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib1f(location(), rhs.r); } void operator = (const color1d& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib1d(location(), rhs.r); } void operator = (const color2f& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib2f(location(), rhs.r, rhs.g); } void operator = (const color2d& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib2d(location(), rhs.r, rhs.g); } void operator = (const color3f& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib3f(location(), rhs.r, rhs.g, rhs.b); } void operator = (const color3d& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib3d(location(), rhs.r, rhs.g, rhs.b); } void operator = (const color4f& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib4f(location(), rhs.r, rhs.g, rhs.b, rhs.a); } void operator = (const color4d& rhs) const { glDisableVertexAttribArray(location()); glVertexAttrib4d(location(), rhs.r, rhs.g, rhs.b, rhs.a); } void operator = (buffer_pointer& pointer) const { pointer.get_vao().enable_for_attribute(m_location); glVertexAttribPointer(location(), pointer.size(), static_cast<GLenum>(pointer.get_type()), pointer.normalize(), pointer.stride(), reinterpret_cast<const void*>(u64{ pointer.offset() })); } }; }
6,586
C++
.h
252
21.456349
147
0.645519
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,150
blitter.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/blitter.h
#pragma once #include "common.h" #include "fbo.h" namespace gl { class command_context; class texture; class blitter { struct save_binding_state { GLuint old_fbo; save_binding_state() { glGetIntegerv(GL_FRAMEBUFFER_BINDING, reinterpret_cast<GLint*>(&old_fbo)); } ~save_binding_state() { glBindFramebuffer(GL_FRAMEBUFFER, old_fbo); } }; fbo blit_src; fbo blit_dst; public: void init() { blit_src.create(); blit_dst.create(); } void destroy() { blit_dst.remove(); blit_src.remove(); } void scale_image(gl::command_context& cmd, const texture* src, texture* dst, areai src_rect, areai dst_rect, bool linear_interpolation, const rsx::typeless_xfer& xfer_info); void copy_image(gl::command_context& cmd, const texture* src, const texture* dst, int src_level, int dst_level, const position3i& src_offset, const position3i& dst_offset, const size3i& size) const; void fast_clear_image(gl::command_context& cmd, const texture* dst, const color4f& color); void fast_clear_image(gl::command_context& cmd, const texture* dst, float depth, u8 stencil); void copy_image(gl::command_context& cmd, const texture* src, const texture* dst, int src_level, int dst_level, const position3u& src_offset, const position3u& dst_offset, const size3u& size) const { copy_image(cmd, src, dst, src_level, dst_level, static_cast<position3i>(src_offset), static_cast<position3i>(dst_offset), static_cast<size3i>(size)); } }; extern blitter* g_hw_blitter; }
1,592
C++
.h
46
30.043478
201
0.697628
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,151
capabilities.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/capabilities.h
#pragma once #include "../OpenGL.h" #include <util/types.hpp> #include <util/asm.hpp> #include <util/logs.hpp> namespace gl { struct version_info { u8 version_major = 0; u8 version_minor = 0; u16 version = 0; version_info() = default; version_info(const char* version_string, int major_scale = 100); }; class capabilities { public: bool initialized = false; version_info glsl_version; bool EXT_dsa_supported = false; bool EXT_depth_bounds_test = false; bool AMD_pinned_memory = false; bool ARB_dsa_supported = false; bool ARB_bindless_texture_supported = false; bool ARB_buffer_storage_supported = false; bool ARB_texture_buffer_supported = false; bool ARB_shader_draw_parameters_supported = false; bool ARB_depth_buffer_float_supported = false; bool ARB_texture_barrier_supported = false; bool ARB_shader_stencil_export_supported = false; bool NV_texture_barrier_supported = false; bool NV_gpu_shader5_supported = false; bool AMD_gpu_shader_half_float_supported = false; bool ARB_compute_shader_supported = false; bool NV_depth_buffer_float_supported = false; bool NV_fragment_shader_barycentric_supported = false; bool vendor_INTEL = false; // has broken GLSL compiler bool vendor_AMD = false; // has broken ARB_multidraw bool vendor_NVIDIA = false; // has NaN poisoning issues bool vendor_MESA = false; // requires CLIENT_STORAGE bit set for streaming buffers bool subvendor_RADEONSI = false; bool subvendor_NOUVEAU = false; bool subvendor_ATI = false; // Pre-GCN cards (terascale, evergreen) void initialize(); private: bool check(const std::string& ext_name, const char* test); }; const capabilities& get_driver_caps(); }
1,776
C++
.h
50
31.66
87
0.723068
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,152
image.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/image.h
#pragma once #include "common.h" #include "Utilities/geometry.h" #include "Emu/RSX/Common/TextureUtils.h" //using enum rsx::format_class; using namespace ::rsx::format_class_; namespace gl { #define GL_BGRA8 0x80E1 // Enumerant of GL_BGRA8_EXT from the GL_EXT_texture_format_BGRA8888 #define GL_BGR5_A1 0x99F0 // Unused enum 0x96xx is the last official GL enumerant class buffer; class buffer_view; class command_context; class pixel_pack_settings; class pixel_unpack_settings; enum image_aspect : u32 { color = 1, depth = 2, stencil = 4 }; enum class filter { nearest = GL_NEAREST, linear = GL_LINEAR }; enum class min_filter { nearest = GL_NEAREST, linear = GL_LINEAR, nearest_mipmap_nearest = GL_NEAREST_MIPMAP_NEAREST, nearest_mipmap_linear = GL_NEAREST_MIPMAP_LINEAR, linear_mipmap_nearest = GL_LINEAR_MIPMAP_NEAREST, linear_mipmap_linear = GL_LINEAR_MIPMAP_LINEAR }; enum remap_constants : u32 { GL_REMAP_IDENTITY = 0xCAFEBABE, GL_REMAP_BGRA = 0x0000AA6C }; struct subresource_range { GLenum aspect_mask; GLuint min_level; GLuint num_levels; GLuint min_layer; GLuint num_layers; }; class texture { friend class texture_view; public: enum class type { ubyte = GL_UNSIGNED_BYTE, ushort = GL_UNSIGNED_SHORT, uint = GL_UNSIGNED_INT, ubyte_3_3_2 = GL_UNSIGNED_BYTE_3_3_2, ubyte_2_3_3_rev = GL_UNSIGNED_BYTE_2_3_3_REV, ushort_5_6_5 = GL_UNSIGNED_SHORT_5_6_5, ushort_5_6_5_rev = GL_UNSIGNED_SHORT_5_6_5_REV, ushort_4_4_4_4 = GL_UNSIGNED_SHORT_4_4_4_4, ushort_4_4_4_4_rev = GL_UNSIGNED_SHORT_4_4_4_4_REV, ushort_5_5_5_1 = GL_UNSIGNED_SHORT_5_5_5_1, ushort_1_5_5_5_rev = GL_UNSIGNED_SHORT_1_5_5_5_REV, uint_8_8_8_8 = GL_UNSIGNED_INT_8_8_8_8, uint_8_8_8_8_rev = GL_UNSIGNED_INT_8_8_8_8_REV, uint_10_10_10_2 = GL_UNSIGNED_INT_10_10_10_2, uint_2_10_10_10_rev = GL_UNSIGNED_INT_2_10_10_10_REV, uint_24_8 = GL_UNSIGNED_INT_24_8, float32_uint8 = GL_FLOAT_32_UNSIGNED_INT_24_8_REV, sbyte = GL_BYTE, sshort = GL_SHORT, sint = GL_INT, f16 = GL_HALF_FLOAT, f32 = GL_FLOAT, f64 = GL_DOUBLE, }; enum class channel { zero = GL_ZERO, one = GL_ONE, r = GL_RED, g = GL_GREEN, b = GL_BLUE, a = GL_ALPHA, }; enum class format { r = GL_RED, rg = GL_RG, rgb = GL_RGB, rgba = GL_RGBA, bgr = GL_BGR, bgra = GL_BGRA, stencil = GL_STENCIL_INDEX, depth = GL_DEPTH_COMPONENT, depth_stencil = GL_DEPTH_STENCIL }; enum class internal_format { stencil8 = GL_STENCIL_INDEX8, depth16 = GL_DEPTH_COMPONENT16, depth32f = GL_DEPTH_COMPONENT32F, depth24_stencil8 = GL_DEPTH24_STENCIL8, depth32f_stencil8 = GL_DEPTH32F_STENCIL8, compressed_rgb_s3tc_dxt1 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT, compressed_rgba_s3tc_dxt1 = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, compressed_rgba_s3tc_dxt3 = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, compressed_rgba_s3tc_dxt5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, //Sized internal formats, see opengl spec document on glTexImage2D, table 3 rgba8 = GL_RGBA8, bgra8 = GL_BGRA8, rgb565 = GL_RGB565, rgb5a1 = GL_RGB5_A1, bgr5a1 = GL_BGR5_A1, rgba4 = GL_RGBA4, r8 = GL_R8, r16 = GL_R16, r32f = GL_R32F, rg8 = GL_RG8, rg16 = GL_RG16, rg16f = GL_RG16F, rgba16f = GL_RGBA16F, rgba32f = GL_RGBA32F, rg8_snorm = GL_RG8_SNORM }; enum class wrap { repeat = GL_REPEAT, mirrored_repeat = GL_MIRRORED_REPEAT, clamp_to_edge = GL_CLAMP_TO_EDGE, clamp_to_border = GL_CLAMP_TO_BORDER, mirror_clamp = GL_MIRROR_CLAMP_EXT, //mirror_clamp_to_edge = GL_MIRROR_CLAMP_TO_EDGE, mirror_clamp_to_border = GL_MIRROR_CLAMP_TO_BORDER_EXT }; enum class compare_mode { none = GL_NONE, ref_to_texture = GL_COMPARE_REF_TO_TEXTURE }; enum class target { texture1D = GL_TEXTURE_1D, texture2D = GL_TEXTURE_2D, texture3D = GL_TEXTURE_3D, textureCUBE = GL_TEXTURE_CUBE_MAP, textureBuffer = GL_TEXTURE_BUFFER, texture2DArray = GL_TEXTURE_2D_ARRAY }; protected: GLuint m_id = GL_NONE; GLuint m_width = 0; GLuint m_height = 0; GLuint m_depth = 0; GLuint m_mipmaps = 0; GLuint m_pitch = 0; GLuint m_compressed = GL_FALSE; GLuint m_aspect_flags = 0; target m_target = target::texture2D; internal_format m_internal_format = internal_format::rgba8; std::array<GLenum, 4> m_component_layout; rsx::format_class m_format_class = RSX_FORMAT_CLASS_UNDEFINED; public: texture(const texture&) = delete; texture(texture&& texture_) = delete; texture(GLenum target, GLuint width, GLuint height, GLuint depth, GLuint mipmaps, GLenum sized_format, rsx::format_class format_class = rsx::RSX_FORMAT_CLASS_UNDEFINED); virtual ~texture(); // Getters/setters void set_native_component_layout(const std::array<GLenum, 4>& layout) { m_component_layout[0] = layout[0]; m_component_layout[1] = layout[1]; m_component_layout[2] = layout[2]; m_component_layout[3] = layout[3]; } target get_target() const noexcept { return m_target; } static bool compressed_format(internal_format format_) noexcept { switch (format_) { case internal_format::compressed_rgb_s3tc_dxt1: case internal_format::compressed_rgba_s3tc_dxt1: case internal_format::compressed_rgba_s3tc_dxt3: case internal_format::compressed_rgba_s3tc_dxt5: return true; default: return false; } } uint id() const noexcept { return m_id; } explicit operator bool() const noexcept { return (m_id != GL_NONE); } GLuint width() const { return m_width; } GLuint height() const { return m_height; } GLuint depth() const { return m_depth; } GLuint levels() const { return m_mipmaps; } GLuint layers() const { switch (m_target) { case target::textureCUBE: return 6; case target::texture2DArray: return m_depth; default: return 1; } } GLuint pitch() const { return m_pitch; } constexpr GLubyte samples() const { return 1; } GLboolean compressed() const { return m_compressed; } GLuint aspect() const { return m_aspect_flags; } rsx::format_class format_class() const { return m_format_class; } sizeu size2D() const { return{ m_width, m_height }; } size3u size3D() const { const auto depth = (m_target == target::textureCUBE) ? 6 : m_depth; return{ m_width, m_height, depth }; } texture::internal_format get_internal_format() const { return m_internal_format; } std::array<GLenum, 4> get_native_component_layout() const { return m_component_layout; } // Data management void copy_from(const void* src, texture::format format, texture::type type, int level, const coord3u region, const pixel_unpack_settings& pixel_settings); void copy_from(buffer& buf, u32 gl_format_type, u32 offset, u32 length); void copy_from(buffer_view& view); void copy_to(void* dst, texture::format format, texture::type type, int level, const coord3u& region, const pixel_pack_settings& pixel_settings) const; // Convenience wrappers void copy_from(const void* src, texture::format format, texture::type type, const pixel_unpack_settings& pixel_settings) { const coord3u region = { {}, size3D() }; copy_from(src, format, type, 0, region, pixel_settings); } void copy_to(void* dst, texture::format format, texture::type type, const pixel_pack_settings& pixel_settings) const { const coord3u region = { {}, size3D() }; copy_to(dst, format, type, 0, region, pixel_settings); } }; class texture_view { protected: GLuint m_id = GL_NONE; GLenum m_target = 0; GLenum m_format = 0; GLenum m_view_format = 0; GLenum m_aspect_flags = 0; texture* m_image_data = nullptr; GLenum component_swizzle[4]; texture_view() = default; void create(texture* data, GLenum target, GLenum sized_format, const subresource_range& range, const GLenum* argb_swizzle = nullptr); public: texture_view(const texture_view&) = delete; texture_view(texture_view&&) = delete; texture_view(texture* data, GLenum target, GLenum sized_format, const GLenum* argb_swizzle = nullptr, GLenum aspect_flags = image_aspect::color | image_aspect::depth) { create(data, target, sized_format, { aspect_flags, 0, data->levels(), 0, data->layers() }, argb_swizzle); } texture_view(texture* data, const GLenum* argb_swizzle = nullptr, GLenum aspect_flags = image_aspect::color | image_aspect::depth) { GLenum target = static_cast<GLenum>(data->get_target()); GLenum sized_format = static_cast<GLenum>(data->get_internal_format()); create(data, target, sized_format, { aspect_flags, 0, data->levels(), 0, data->layers() }, argb_swizzle); } texture_view(texture* data, const subresource_range& range, const GLenum* argb_swizzle = nullptr) { GLenum target = static_cast<GLenum>(data->get_target()); GLenum sized_format = static_cast<GLenum>(data->get_internal_format()); create(data, target, sized_format, range, argb_swizzle); } texture_view(texture* data, GLenum target, const subresource_range& range, const GLenum* argb_swizzle = nullptr) { GLenum sized_format = static_cast<GLenum>(data->get_internal_format()); create(data, target, sized_format, range, argb_swizzle); } virtual ~texture_view(); GLuint id() const { return m_id; } GLenum target() const { return m_target; } GLenum internal_format() const { return m_format; } GLenum view_format() const { return m_view_format; } GLenum aspect() const { return m_aspect_flags; } bool compare_swizzle(const GLenum* argb_swizzle) const { return (argb_swizzle[0] == component_swizzle[3] && argb_swizzle[1] == component_swizzle[0] && argb_swizzle[2] == component_swizzle[1] && argb_swizzle[3] == component_swizzle[2]); } texture* image() const { return m_image_data; } std::array<GLenum, 4> component_mapping() const { return{ component_swizzle[3], component_swizzle[0], component_swizzle[1], component_swizzle[2] }; } u32 encoded_component_map() const { // Unused, OGL supports proper component swizzles return 0u; } void bind(gl::command_context& cmd, GLuint layer) const; }; // Passthrough texture view that simply wraps the original texture in a texture_view interface class nil_texture_view : public texture_view { public: nil_texture_view(texture* data); ~nil_texture_view(); }; class viewable_image : public texture { std::unordered_map<u64, std::unique_ptr<texture_view>> views; public: using texture::texture; texture_view* get_view(const rsx::texture_channel_remap_t& remap, GLenum aspect_flags = image_aspect::color | image_aspect::depth); void set_native_component_layout(const std::array<GLenum, 4>& layout); }; // Texture helpers std::array<GLenum, 4> apply_swizzle_remap(const std::array<GLenum, 4>& swizzle_remap, const rsx::texture_channel_remap_t& decoded_remap); }
11,531
C++
.h
386
25.207254
172
0.671615
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,153
sync.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/sync.hpp
#pragma once #include "common.h" namespace gl { class fence { GLsync m_value = nullptr; mutable GLenum flags = GL_SYNC_FLUSH_COMMANDS_BIT; mutable bool signaled = false; public: fence() = default; ~fence() = default; void create() { m_value = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); flags = GL_SYNC_FLUSH_COMMANDS_BIT; } void destroy() { glDeleteSync(m_value); m_value = nullptr; } void reset() { if (m_value != nullptr) destroy(); create(); } bool is_empty() const { return (m_value == nullptr); } bool check_signaled() const { ensure(m_value); if (signaled) return true; if (flags) { GLenum err = glClientWaitSync(m_value, flags, 0); flags = 0; if (!(err == GL_ALREADY_SIGNALED || err == GL_CONDITION_SATISFIED)) return false; } else { GLint status = GL_UNSIGNALED; GLint tmp; glGetSynciv(m_value, GL_SYNC_STATUS, 4, &tmp, &status); if (status != GL_SIGNALED) return false; } signaled = true; return true; } bool wait_for_signal() { ensure(m_value); if (signaled == GL_FALSE) { GLenum err = GL_WAIT_FAILED; bool done = false; while (!done) { if (flags) { err = glClientWaitSync(m_value, flags, 0); flags = 0; switch (err) { default: rsx_log.error("gl::fence sync returned unknown error 0x%X", err); [[fallthrough]]; case GL_ALREADY_SIGNALED: case GL_CONDITION_SATISFIED: done = true; break; case GL_TIMEOUT_EXPIRED: continue; } } else { GLint status = GL_UNSIGNALED; GLint tmp; glGetSynciv(m_value, GL_SYNC_STATUS, 4, &tmp, &status); if (status == GL_SIGNALED) break; } } signaled = (err == GL_ALREADY_SIGNALED || err == GL_CONDITION_SATISFIED); } glDeleteSync(m_value); m_value = nullptr; return signaled; } void server_wait_sync() const { ensure(m_value != nullptr); glWaitSync(m_value, 0, GL_TIMEOUT_IGNORED); } }; }
2,238
C++
.h
103
15.786408
78
0.575612
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,154
ring_buffer.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/ring_buffer.h
#pragma once #include "buffer_object.h" #include "sync.hpp" #include "Utilities/address_range.h" namespace gl { class ring_buffer : public buffer { protected: u32 m_data_loc = 0; void* m_memory_mapping = nullptr; fence m_fence; public: virtual ~ring_buffer() = default; virtual void bind() { buffer::bind(); } virtual void recreate(GLsizeiptr size, const void* data = nullptr); void create(target target_, GLsizeiptr size, const void* data_ = nullptr); virtual std::pair<void*, u32> alloc_from_heap(u32 alloc_size, u16 alignment); virtual void remove(); virtual void reserve_storage_on_heap(u32 /*alloc_size*/) {} virtual void unmap() {} virtual void flush() {} virtual void notify(); }; class legacy_ring_buffer final : public ring_buffer { u32 m_mapped_bytes = 0; u32 m_mapping_offset = 0; u32 m_alignment_offset = 0; public: void recreate(GLsizeiptr size, const void* data = nullptr) override; void create(target target_, GLsizeiptr size, const void* data_ = nullptr); void reserve_storage_on_heap(u32 alloc_size) override; std::pair<void*, u32> alloc_from_heap(u32 alloc_size, u16 alignment) override; void remove() override; void unmap() override; void notify() override {} }; // A non-persistent ring buffer // Internally maps and unmaps data. Uses persistent storage just like the regular persistent variant // Works around drivers that have issues using mapped data for specific sources (e.g AMD proprietary driver with index buffers) class transient_ring_buffer final : public ring_buffer { bool dirty = false; void* map_internal(u32 offset, u32 length); public: void bind() override; void recreate(GLsizeiptr size, const void* data = nullptr) override; std::pair<void*, u32> alloc_from_heap(u32 alloc_size, u16 alignment) override; void flush() override; void unmap() override; }; // Simple GPU-side ring buffer with no map/unmap semantics class scratch_ring_buffer { struct barrier { fence signal; utils::address_range range; }; buffer m_storage; std::vector<barrier> m_barriers; u64 m_alloc_pointer = 0; void pop_barrier(u32 start, u32 length); public: scratch_ring_buffer() = default; scratch_ring_buffer(const scratch_ring_buffer&) = delete; ~scratch_ring_buffer(); void create(buffer::target _target, u64 size, u32 usage_flags = 0); void remove(); u32 alloc(u32 size, u32 alignment); void push_barrier(u32 start, u32 length); buffer& get() { return m_storage; } u64 size() const { return m_storage.size(); } }; }
2,699
C++
.h
76
30.947368
129
0.707777
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,155
state_tracker.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/state_tracker.hpp
#pragma once #include "capabilities.h" #include "Utilities/geometry.h" #include <unordered_map> namespace gl { class driver_state { const u32 DEPTH_BOUNDS = 0xFFFF0001; const u32 CLIP_PLANES = 0xFFFF0002; const u32 DEPTH_RANGE = 0xFFFF0004; const u32 STENCIL_FRONT_FUNC = 0xFFFF0005; const u32 STENCIL_BACK_FUNC = 0xFFFF0006; const u32 STENCIL_FRONT_OP = 0xFFFF0007; const u32 STENCIL_BACK_OP = 0xFFFF0008; const u32 STENCIL_BACK_MASK = 0xFFFF0009; std::unordered_map<GLenum, u64> properties = {}; std::unordered_map<GLenum, std::array<u64, 4>> indexed_properties = {}; GLuint current_program = GL_NONE; std::array<std::unordered_map<GLenum, GLuint>, 48> bound_textures{ {} }; bool test_and_set_property(GLenum property, u64 test) { auto found = properties.find(property); if (found != properties.end() && found->second == test) return true; properties[property] = test; return false; } bool test_and_set_property(GLenum property, u64 test, GLint index) { auto found = indexed_properties.find(property); if (found != indexed_properties.end()) { if (found->second[index] == test) { return true; } found->second[index] = test; return false; } indexed_properties[property][index] = test; return false; } public: bool enable(u32 test, GLenum cap) { auto found = properties.find(cap); if (found != properties.end() && found->second == test) return !!test; properties[cap] = test; if (test) glEnable(cap); else glDisable(cap); return !!test; } bool enablei(u32 test, GLenum cap, u32 index) { auto found = indexed_properties.find(cap); const bool exists = found != indexed_properties.end(); if (!exists) { indexed_properties[cap] = {}; indexed_properties[cap][index] = test; } else { if (found->second[index] == test) return !!test; found->second[index] = test; } if (test) glEnablei(cap, index); else glDisablei(cap, index); return !!test; } bool enable(GLenum cap) { return enable(GL_TRUE, cap); } bool enablei(GLenum cap, u32 index) { return enablei(GL_TRUE, cap, index); } bool disable(GLenum cap) { return enable(GL_FALSE, cap); } bool disablei(GLenum cap, u32 index) { return enablei(GL_FALSE, cap, index); } void depth_func(GLenum func) { if (!test_and_set_property(GL_DEPTH_FUNC, func)) { glDepthFunc(func); } } void depth_mask(GLboolean mask) { if (!test_and_set_property(GL_DEPTH_WRITEMASK, mask)) { glDepthMask(mask); } } void clear_depth(GLfloat depth) { const u32 value = std::bit_cast<u32>(depth); if (!test_and_set_property(GL_DEPTH_CLEAR_VALUE, value)) { glClearDepth(depth); } } void stencil_mask(GLuint mask) { if (!test_and_set_property(GL_STENCIL_WRITEMASK, mask)) { glStencilMask(mask); } } void stencil_back_mask(GLuint mask) { if (!test_and_set_property(STENCIL_BACK_MASK, mask)) { glStencilMaskSeparate(GL_BACK, mask); } } void clear_stencil(GLint stencil) { const u32 value = std::bit_cast<u32>(stencil); if (!test_and_set_property(GL_STENCIL_CLEAR_VALUE, value)) { glClearStencil(stencil); } } void stencil_func(GLenum func, GLint ref, GLuint mask) { const u32 value = func | ref << 16u | mask << 24; if (!test_and_set_property(STENCIL_FRONT_FUNC, value)) { glStencilFunc(func, ref, mask); } } void stencil_back_func(GLenum func, GLint ref, GLuint mask) { const u32 value = func | ref << 16u | mask << 24; if (!test_and_set_property(STENCIL_BACK_FUNC, value)) { glStencilFunc(func, ref, mask); } } void stencil_op(GLenum fail, GLenum zfail, GLenum zpass) { const u64 value = static_cast<u64>(fail) << 32 | static_cast<u64>(zfail) << 16 | static_cast<u64>(zpass); if (!test_and_set_property(STENCIL_FRONT_OP, value)) { glStencilOp(fail, zfail, zpass); } } void stencil_back_op(GLenum fail, GLenum zfail, GLenum zpass) { const u64 value = static_cast<u64>(fail) << 32 | static_cast<u64>(zfail) << 16 | static_cast<u64>(zpass); if (!test_and_set_property(STENCIL_BACK_OP, value)) { glStencilOpSeparate(GL_BACK, fail, zfail, zpass); } } void color_maski(GLint index, u32 mask) { if (!test_and_set_property(GL_COLOR_WRITEMASK, mask, index)) { glColorMaski(index, ((mask & 0x10) ? 1 : 0), ((mask & 0x20) ? 1 : 0), ((mask & 0x40) ? 1 : 0), ((mask & 0x80) ? 1 : 0)); } } void color_maski(GLint index, bool r, bool g, bool b, bool a) { u32 mask = 0; if (r) mask |= 0x10; if (g) mask |= 0x20; if (b) mask |= 0x40; if (a) mask |= 0x80; color_maski(index, mask); } void clear_color(u8 r, u8 g, u8 b, u8 a) { const u32 value = u32{ r } | u32{ g } << 8 | u32{ b } << 16 | u32{ a } << 24; if (!test_and_set_property(GL_COLOR_CLEAR_VALUE, value)) { glClearColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f); } } void clear_color(const color4f& color) { clear_color(static_cast<u8>(color.r * 255), static_cast<u8>(color.g * 255), static_cast<u8>(color.b * 255), static_cast<u8>(color.a * 255)); } void depth_bounds(float min, float max) { const u64 value = (static_cast<u64>(std::bit_cast<u32>(max)) << 32) | std::bit_cast<u32>(min); if (!test_and_set_property(DEPTH_BOUNDS, value)) { if (get_driver_caps().NV_depth_buffer_float_supported) { glDepthBoundsdNV(min, max); } else { glDepthBoundsEXT(min, max); } } } void depth_range(float min, float max) { const u64 value = (static_cast<u64>(std::bit_cast<u32>(max)) << 32) | std::bit_cast<u32>(min); if (!test_and_set_property(DEPTH_RANGE, value)) { if (get_driver_caps().NV_depth_buffer_float_supported) { glDepthRangedNV(min, max); } else { glDepthRange(min, max); } } } void logic_op(GLenum op) { if (!test_and_set_property(GL_COLOR_LOGIC_OP, op)) { glLogicOp(op); } } void line_width(GLfloat width) { u32 value = std::bit_cast<u32>(width); if (!test_and_set_property(GL_LINE_WIDTH, value)) { glLineWidth(width); } } void front_face(GLenum face) { if (!test_and_set_property(GL_FRONT_FACE, face)) { glFrontFace(face); } } void cull_face(GLenum mode) { if (!test_and_set_property(GL_CULL_FACE_MODE, mode)) { glCullFace(mode); } } void polygon_offset(float factor, float units) { const u64 value = (static_cast<u64>(std::bit_cast<u32>(units)) << 32) | std::bit_cast<u32>(factor); if (!test_and_set_property(GL_POLYGON_OFFSET_FILL, value)) { glPolygonOffset(factor, units); } } void clip_planes(GLuint mask) { if (!test_and_set_property(CLIP_PLANES, mask)) { for (u32 i = 0; i < 6; ++i) { if (mask & (1 << i)) { glEnable(GL_CLIP_DISTANCE0 + i); } else { glDisable(GL_CLIP_DISTANCE0 + i); } } } } void use_program(GLuint program) { if (current_program == program) { return; } current_program = program; glUseProgram(program); } GLuint get_bound_texture(GLuint layer, GLenum target) { ensure(layer < 48); return bound_textures[layer][target]; } void bind_texture(GLuint layer, GLenum target, GLuint name, GLboolean force = GL_FALSE) { ensure(layer < 48); auto& bound = bound_textures[layer][target]; if (bound != name || force) { glActiveTexture(GL_TEXTURE0 + layer); glBindTexture(target, name); bound = name; } } void unbind_texture(GLenum target, GLuint name) { // To be called with glDeleteTextures. // OpenGL internally unbinds the texture on delete, but then reuses the same ID when GenTextures is called again! // This can also be avoided using unique internal names, such as 64-bit handles, but that involves changing a lot of code for little benefit for (auto& layer : bound_textures) { if (layer.empty()) { continue; } if (auto found = layer.find(target); found != layer.end() && found->second == name) { // Actually still bound! found->second = GL_NONE; return; } } } }; class command_context { driver_state* drv; public: command_context() : drv(nullptr) {} command_context(driver_state& drv_) : drv(&drv_) {} driver_state* operator -> () { return drv; } }; void set_command_context(gl::command_context& ctx); void set_command_context(gl::driver_state& ctx); gl::command_context get_command_context(); void set_primary_context_thread(bool = true); bool is_primary_context_thread(); class fence; void flush_command_queue(fence& fence_obj); }
9,272
C++
.h
349
21.426934
144
0.617229
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,156
common.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/common.h
#pragma once #include "capabilities.h" #define GL_FRAGMENT_TEXTURES_START 0 #define GL_VERTEX_TEXTURES_START (GL_FRAGMENT_TEXTURES_START + 16) #define GL_STENCIL_MIRRORS_START (GL_VERTEX_TEXTURES_START + 4) #define GL_STREAM_BUFFER_START (GL_STENCIL_MIRRORS_START + 16) #define GL_TEMP_IMAGE_SLOT(x) (31 - x) #define UBO_SLOT(x) (x + 8) #define SSBO_SLOT(x) (x) #define GL_VERTEX_PARAMS_BIND_SLOT UBO_SLOT(0) #define GL_VERTEX_LAYOUT_BIND_SLOT UBO_SLOT(1) #define GL_VERTEX_CONSTANT_BUFFERS_BIND_SLOT UBO_SLOT(2) #define GL_FRAGMENT_CONSTANT_BUFFERS_BIND_SLOT UBO_SLOT(3) #define GL_FRAGMENT_STATE_BIND_SLOT UBO_SLOT(4) #define GL_FRAGMENT_TEXTURE_PARAMS_BIND_SLOT UBO_SLOT(5) #define GL_RASTERIZER_STATE_BIND_SLOT UBO_SLOT(6) #define GL_INTERPRETER_VERTEX_BLOCK SSBO_SLOT(0) #define GL_INTERPRETER_FRAGMENT_BLOCK SSBO_SLOT(1) #define GL_COMPUTE_BUFFER_SLOT(index) SSBO_SLOT(2 + index) #define GL_COMPUTE_IMAGE_SLOT(index) SSBO_SLOT(index) //Function call wrapped in ARB_DSA vs EXT_DSA compat check #define DSA_CALL(func, object_name, target, ...)\ if (::gl::get_driver_caps().ARB_dsa_supported)\ gl##func(object_name, __VA_ARGS__);\ else\ gl##func##EXT(object_name, target, __VA_ARGS__); #define DSA_CALL2(func, ...)\ if (::gl::get_driver_caps().ARB_dsa_supported)\ gl##func(__VA_ARGS__);\ else\ gl##func##EXT(__VA_ARGS__); #define DSA_CALL2_RET(func, ...)\ (::gl::get_driver_caps().ARB_dsa_supported) ?\ gl##func(__VA_ARGS__) :\ gl##func##EXT(__VA_ARGS__) #define DSA_CALL3(funcARB, funcDSA, ...)\ if (::gl::get_driver_caps().ARB_dsa_supported)\ gl##funcARB(__VA_ARGS__);\ else\ gl##funcDSA##EXT(__VA_ARGS__); namespace gl { using flags32_t = u32; using handle32_t = u32; template<typename Type, uint BindId, uint GetStateId> class save_binding_state_base { GLint m_last_binding; public: save_binding_state_base(const Type& new_state) : save_binding_state_base() { new_state.bind(); } save_binding_state_base() { glGetIntegerv(GetStateId, &m_last_binding); } ~save_binding_state_base() { glBindBuffer(BindId, m_last_binding); } }; // Very useful util when capturing traces with RenderDoc static inline void push_debug_label(const char* label) { glInsertEventMarkerEXT(static_cast<GLsizei>(strlen(label)), label); } // Checks if GL state is still valid static inline void check_state() { // GL_OUT_OF_MEMORY invalidates the OpenGL context and is actually the GL version of DEVICE_LOST. // This spec workaround allows it to be abused by ISVs to indicate a broken GL context. ensure(glGetError() != GL_OUT_OF_MEMORY); } }
2,802
C++
.h
75
33.96
100
0.675936
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,157
buffer_object.h
RPCS3_rpcs3/rpcs3/Emu/RSX/GL/glutils/buffer_object.h
#pragma once #include "common.h" namespace gl { class buffer { public: enum class target { pixel_pack = GL_PIXEL_PACK_BUFFER, pixel_unpack = GL_PIXEL_UNPACK_BUFFER, array = GL_ARRAY_BUFFER, element_array = GL_ELEMENT_ARRAY_BUFFER, uniform = GL_UNIFORM_BUFFER, texture = GL_TEXTURE_BUFFER, ssbo = GL_SHADER_STORAGE_BUFFER }; enum class access { read = GL_MAP_READ_BIT, write = GL_MAP_WRITE_BIT, rw = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT, persistent_rw = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT }; enum class memory_type { undefined = 0, local = 1, host_visible = 2, userptr = 4 }; enum usage { host_write = (1 << 0), host_read = (1 << 1), persistent_map = (1 << 2), dynamic_update = (1 << 3), }; class save_binding_state { GLint m_last_binding = GL_ZERO; GLenum m_target = GL_NONE; public: save_binding_state(target target_, const buffer& new_state) : save_binding_state(target_) { new_state.bind(target_); } save_binding_state(target target_) { GLenum pname{}; switch (target_) { case target::pixel_pack: pname = GL_PIXEL_PACK_BUFFER_BINDING; break; case target::pixel_unpack: pname = GL_PIXEL_UNPACK_BUFFER_BINDING; break; case target::array: pname = GL_ARRAY_BUFFER_BINDING; break; case target::element_array: pname = GL_ELEMENT_ARRAY_BUFFER_BINDING; break; case target::uniform: pname = GL_UNIFORM_BUFFER_BINDING; break; case target::texture: pname = GL_TEXTURE_BUFFER_BINDING; break; case target::ssbo: pname = GL_SHADER_STORAGE_BUFFER_BINDING; break; default: fmt::throw_exception("Invalid binding state target (0x%x)", static_cast<int>(target_)); } glGetIntegerv(pname, &m_last_binding); m_target = static_cast<GLenum>(target_); } ~save_binding_state() { if (!m_target) { return; } glBindBuffer(m_target, m_last_binding); } }; protected: GLuint m_id = GL_NONE; GLsizeiptr m_size = 0; target m_target = target::array; memory_type m_memory_type = memory_type::undefined; // Metadata mutable std::pair<u32, u32> m_bound_range{}; void allocate(GLsizeiptr size, const void* data_, memory_type type, GLuint usage_bits); public: buffer() = default; buffer(const buffer&) = delete; ~buffer(); void recreate(); void recreate(GLsizeiptr size, const void* data = nullptr); void create(); void create(GLsizeiptr size, const void* data_ = nullptr, memory_type type = memory_type::local, GLuint usage_bits = 0); void create(target target_, GLsizeiptr size, const void* data_ = nullptr, memory_type type = memory_type::local, GLuint usage_bits = 0); void remove(); void bind(target target_) const { glBindBuffer(static_cast<GLenum>(target_), m_id); } void bind() const { bind(current_target()); } void data(GLsizeiptr size, const void* data_ = nullptr, GLenum usage = GL_STREAM_DRAW); void sub_data(GLsizeiptr offset, GLsizeiptr length, const GLvoid* data); GLubyte* map(GLsizeiptr offset, GLsizeiptr length, access access_); void unmap(); void bind_range(u32 index, u32 offset, u32 size) const; void bind_range(target target_, u32 index, u32 offset, u32 size) const; void copy_to(buffer* other, u64 src_offset, u64 dst_offset, u64 size); target current_target() const { return m_target; } GLsizeiptr size() const { return m_size; } uint id() const { return m_id; } void set_id(uint id) { m_id = id; } bool created() const { return m_id != GL_NONE; } std::pair<u32, u32> bound_range() const { return m_bound_range; } explicit operator bool() const { return created(); } }; class buffer_view { buffer* m_buffer = nullptr; u32 m_offset = 0; u32 m_range = 0; GLenum m_format = GL_R8UI; public: buffer_view(buffer* _buffer, u32 offset, u32 range, GLenum format = GL_R8UI) : m_buffer(_buffer), m_offset(offset), m_range(range), m_format(format) {} buffer_view() = default; void update(buffer* _buffer, u32 offset, u32 range, GLenum format = GL_R8UI); u32 offset() const { return m_offset; } u32 range() const { return m_range; } u32 format() const { return m_format; } buffer* value() const { return m_buffer; } bool in_range(u32 address, u32 size, u32& new_offset) const; }; }
4,491
C++
.h
127
30.417323
139
0.66108
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,158
RSXFrameBuffer.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Core/RSXFrameBuffer.h
#pragma once #include <util/types.hpp> #include "../gcm_enums.h" #include "../GCM.h" namespace rsx { struct tiled_region { u32 address; u32 base; GcmTileInfo* tile; u8* ptr; void write(const void* src, u32 width, u32 height, u32 pitch); void read(void* dst, u32 width, u32 height, u32 pitch); }; struct framebuffer_layout { ENABLE_BITWISE_SERIALIZATION; u16 width; u16 height; std::array<u32, 4> color_addresses; std::array<u32, 4> color_pitch; std::array<u32, 4> actual_color_pitch; std::array<bool, 4> color_write_enabled; u32 zeta_address; u32 zeta_pitch; u32 actual_zeta_pitch; bool zeta_write_enabled; rsx::surface_target target; rsx::surface_color_format color_format; rsx::surface_depth_format2 depth_format; rsx::surface_antialiasing aa_mode; rsx::surface_raster_type raster_type; u32 aa_factors[2]; bool ignore_change; }; }
934
C++
.h
37
21.513514
65
0.696731
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,159
RSXIOMap.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/Core/RSXIOMap.hpp
#pragma once #include <util/types.hpp> #include "Utilities/mutex.h" #include "Emu/CPU/CPUThread.h" namespace rsx { namespace iomap_helper { template <bool Shared> struct io_lock { shared_mutex& ref; io_lock(shared_mutex& obj) : ref(obj) {} bool try_lock() { if constexpr (Shared) { return ref.try_lock_shared(); } return ref.try_lock(); } void lock() { if constexpr (Shared) { ref.lock_shared(); return; } ref.lock(); } }; } struct rsx_iomap_table { static constexpr u32 c_lock_stride = 8192; std::array<atomic_t<u32>, 4096> ea; std::array<atomic_t<u32>, 4096> io; std::array<shared_mutex, 0x1'0000'0000 / c_lock_stride> rs; rsx_iomap_table() noexcept; // Try to get the real address given a mapped address // Returns -1 on failure u32 get_addr(u32 offs) const noexcept { return this->ea[offs >> 20] | (offs & 0xFFFFF); } template <bool IsFullLock, uint Stride> bool lock(u32 addr, u32 len, cpu_thread* self = nullptr) noexcept { if (len <= 1) return false; const u32 end = addr + len - 1; bool added_wait = false; for (u32 block = addr / c_lock_stride; block <= (end / c_lock_stride); block += Stride) { auto mutex_ = iomap_helper::io_lock<!IsFullLock>(rs[block]); if (!mutex_.try_lock()) [[ unlikely ]] { if (self) { added_wait |= !self->state.test_and_set(cpu_flag::wait); } if (!self || self->get_class() != thread_class::rsx) { mutex_.lock(); continue; } while (!mutex_.try_lock()) { self->cpu_wait({}); } } } if (added_wait) { self->check_state(); } return true; } template <bool IsFullLock, uint Stride> void unlock(u32 addr, u32 len) noexcept { ensure(len >= 1); const u32 end = addr + len - 1; for (u32 block = (addr / 8192); block <= (end / 8192); block += Stride) { if constexpr (IsFullLock) { rs[block].unlock(); } else { rs[block].unlock_shared(); } } } }; }
2,211
C++
.h
98
17.081633
91
0.568807
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,160
RSXDisplay.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Core/RSXDisplay.h
#pragma once #include <util/types.hpp> #include <util/logs.hpp> #include <deque> namespace rsx { struct frame_statistics_t { u32 draw_calls; u32 submit_count; s64 setup_time; s64 vertex_upload_time; s64 textures_upload_time; s64 draw_exec_time; s64 flip_time; u32 vertex_cache_request_count; u32 vertex_cache_miss_count; }; struct frame_time_t { u64 preempt_count; u64 timestamp; u64 tsc; }; struct display_flip_info_t { std::deque<u32> buffer_queue; u32 buffer; bool skip_frame; bool emu_flip; bool in_progress; frame_statistics_t stats; inline void push(u32 _buffer) { buffer_queue.push_back(_buffer); } inline bool pop(u32 _buffer) { if (buffer_queue.empty()) { return false; } do { const auto index = buffer_queue.front(); buffer_queue.pop_front(); if (index == _buffer) { buffer = _buffer; return true; } } while (!buffer_queue.empty()); // Need to observe this happening in the wild rsx_log.error("Display queue was discarded while not empty!"); return false; } }; class vblank_thread { std::shared_ptr<named_thread<std::function<void()>>> m_thread; public: vblank_thread() = default; vblank_thread(const vblank_thread&) = delete; void set_thread(std::shared_ptr<named_thread<std::function<void()>>> thread); vblank_thread& operator=(thread_state); vblank_thread& operator=(const vblank_thread&) = delete; }; }
1,552
C++
.h
68
18.367647
80
0.660248
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,161
RSXReservationLock.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/Core/RSXReservationLock.hpp
#pragma once #include <util/types.hpp> #include "../RSXThread.h" namespace rsx { template<bool IsFullLock = false, uint Stride = 128> class reservation_lock { u32 addr = 0; u32 length = 0; inline void lock_range(u32 addr, u32 length) { if (!get_current_renderer()->iomap_table.lock<IsFullLock, Stride>(addr, length, get_current_cpu_thread())) { length = 0; } this->addr = addr; this->length = length; } public: reservation_lock(u32 addr, u32 length) { if (g_cfg.core.rsx_accurate_res_access && addr < constants::local_mem_base) { lock_range(addr, length); } } reservation_lock(u32 addr, u32 length, bool setting) { if (setting) { lock_range(addr, length); } } // Multi-range lock. If ranges overlap, the combined range will be acquired. // If ranges do not overlap, the first range that is in main memory will be acquired. reservation_lock(u32 dst_addr, u32 dst_length, u32 src_addr, u32 src_length) { if (!g_cfg.core.rsx_accurate_res_access) { return; } const auto range1 = utils::address_range::start_length(dst_addr, dst_length); const auto range2 = utils::address_range::start_length(src_addr, src_length); utils::address_range target_range; if (!range1.overlaps(range2)) [[likely]] { target_range = (dst_addr < constants::local_mem_base) ? range1 : range2; } else { // Very unlikely target_range = range1.get_min_max(range2); } if (target_range.start < constants::local_mem_base) { lock_range(target_range.start, target_range.length()); } } // Very special utility for batched transfers (SPU related) template <typename T = void> void update_if_enabled(u32 addr, u32 _length, const std::add_pointer_t<T>& lock_release = std::add_pointer_t<void>{}) { if (!length) { unlock(); return; } // This check is not perfect but it covers the important cases fast (this check is only an optimization - forcing true disables it) const bool should_update = (this->addr / rsx_iomap_table::c_lock_stride) != (addr / rsx_iomap_table::c_lock_stride) || // Lock-addr and test-addr have different locks, update (addr % rsx_iomap_table::c_lock_stride + _length) > rsx_iomap_table::c_lock_stride; // Test range spills beyond our base section if (!should_update) { return; } if constexpr (!std::is_void_v<T>) { // See SPUThread.cpp lock_release->release(0); } unlock(); lock_range(addr, _length); } void unlock(bool destructor = false) { if (!length) { return; } get_current_renderer()->iomap_table.unlock<IsFullLock, Stride>(addr, length); if (!destructor) { length = 0; } } ~reservation_lock() { unlock(true); } }; }
2,925
C++
.h
103
23.38835
153
0.639009
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,162
RSXEngLock.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/Core/RSXEngLock.hpp
#pragma once #include <util/types.hpp> #include "../RSXThread.h" namespace rsx { class eng_lock { rsx::thread* pthr; public: eng_lock(rsx::thread* target) :pthr(target) { if (pthr->is_current_thread()) { pthr = nullptr; } else { pthr->pause(); } } ~eng_lock() { if (pthr) pthr->unpause(); } }; }
381
C++
.h
27
9.962963
34
0.549133
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,163
RSXContext.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Core/RSXContext.h
#pragma once #include <util/types.hpp> #include "Emu/Cell/lv2/sys_rsx.h" #include "Emu/RSX/GCM.h" #include "Emu/RSX/rsx_utils.h" #include "RSXIOMap.hpp" namespace rsx { namespace gcm { enum limits { tiles_count = 15, zculls_count = 8 }; } struct GCM_tile_reference { u32 base_address = 0; const GcmTileInfo* tile = nullptr; operator bool() const { return !!tile; } utils::address_range tile_align(const rsx::address_range& range) const; }; struct GCM_context { RsxDmaControl* ctrl = nullptr; u32 dma_address{ 0 }; rsx_iomap_table iomap_table; GcmTileInfo tiles[gcm::limits::tiles_count]; GcmZcullInfo zculls[gcm::limits::zculls_count]; RsxDisplayInfo display_buffers[8]; u32 display_buffers_count{ 0 }; u32 current_display_buffer{ 0 }; shared_mutex sys_rsx_mtx; u32 device_addr{ 0 }; u32 label_addr{ 0 }; u32 main_mem_size{ 0 }; u32 local_mem_size{ 0 }; u32 rsx_event_port{ 0 }; u32 driver_info{ 0 }; atomic_t<u64> unsent_gcm_events = 0; // Unsent event bits when aborting RSX/VBLANK thread (will be sent on savestate load) GCM_tile_reference get_tiled_memory_region(const utils::address_range& range) const; }; }
1,253
C++
.h
47
22.702128
125
0.684122
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,164
RSXVertexTypes.h
RPCS3_rpcs3/rpcs3/Emu/RSX/Core/RSXVertexTypes.h
#pragma once #include <util/types.hpp> #include "../Common/simple_array.hpp" #include "../gcm_enums.h" #include <span> namespace rsx { struct vertex_array_buffer { rsx::vertex_base_type type; u8 attribute_size; u8 stride; std::span<const std::byte> data; u8 index; bool is_be; }; struct vertex_array_register { rsx::vertex_base_type type; u8 attribute_size; std::array<u32, 4> data; u8 index; }; struct empty_vertex_array { u8 index; }; struct draw_array_command { u32 __dummy; }; struct draw_indexed_array_command { std::span<const std::byte> raw_index_buffer; }; struct draw_inlined_array { u32 __dummy; u32 __dummy2; }; struct interleaved_attribute_t { u8 index; bool modulo; u16 frequency; }; struct interleaved_range_info { bool interleaved = false; bool single_vertex = false; u32 base_offset = 0; u32 real_offset_address = 0; u8 memory_location = 0; u8 attribute_stride = 0; std::pair<u32, u32> vertex_range{}; rsx::simple_array<interleaved_attribute_t> locations; // Check if we need to upload a full unoptimized range, i.e [0-max_index] std::pair<u32, u32> calculate_required_range(u32 first, u32 count); }; enum attribute_buffer_placement : u8 { none = 0, persistent = 1, transient = 2 }; class vertex_input_layout { int m_num_used_blocks = 0; std::array<interleaved_range_info, 16> m_blocks_data{}; public: rsx::simple_array<interleaved_range_info*> interleaved_blocks{}; // Interleaved blocks to be uploaded as-is std::vector<std::pair<u8, u32>> volatile_blocks{}; // Volatile data blocks (immediate draw vertex data for example) rsx::simple_array<u8> referenced_registers{}; // Volatile register data u16 attribute_mask = 0; // ATTRn mask std::array<attribute_buffer_placement, 16> attribute_placement = fill_array(attribute_buffer_placement::none); vertex_input_layout() = default; interleaved_range_info* alloc_interleaved_block() { auto result = &m_blocks_data[m_num_used_blocks++]; result->attribute_stride = 0; result->base_offset = 0; result->memory_location = 0; result->real_offset_address = 0; result->single_vertex = false; result->locations.clear(); result->interleaved = true; result->vertex_range.second = 0; return result; } void clear() { m_num_used_blocks = 0; attribute_mask = 0; interleaved_blocks.clear(); volatile_blocks.clear(); referenced_registers.clear(); } bool validate() const { // Criteria: At least one array stream has to be defined to feed vertex positions // This stream cannot be a const register as the vertices cannot create a zero-area primitive if (!interleaved_blocks.empty() && interleaved_blocks[0]->attribute_stride != 0) return true; if (!volatile_blocks.empty()) return true; for (u16 ref_mask = attribute_mask, index = 0; ref_mask; ++index, ref_mask >>= 1) { if (!(ref_mask & 1)) { // Disabled continue; } switch (attribute_placement[index]) { case attribute_buffer_placement::transient: { // Ignore register reference if (std::find(referenced_registers.begin(), referenced_registers.end(), index) != referenced_registers.end()) continue; // The source is inline array or immediate draw push buffer return true; } case attribute_buffer_placement::persistent: { return true; } case attribute_buffer_placement::none: { continue; } default: { fmt::throw_exception("Unreachable"); } } } return false; } u32 calculate_interleaved_memory_requirements(u32 first_vertex, u32 vertex_count) const { u32 mem = 0; for (auto& block : interleaved_blocks) { const auto range = block->calculate_required_range(first_vertex, vertex_count); mem += range.second * block->attribute_stride; } return mem; } }; }
4,192
C++
.h
150
23.213333
133
0.651454
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,165
draw_call.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/FW/draw_call.hpp
#pragma once #include "draw_call.inc.h" #include "Emu/RSX/Common/simple_array.hpp" #include "Emu/RSX/gcm_enums.h" namespace rsx { class draw_clause { // Stores the first and count argument from draw/draw indexed parameters between begin/end clauses. simple_array<draw_range_t> draw_command_ranges{}; // Stores rasterization barriers for primitive types sensitive to adjacency simple_array<barrier_t> draw_command_barriers{}; // Counter used to parse the commands in order u32 current_range_index{}; // Location of last execution barrier u32 last_execution_barrier_index{}; // Draw-time iterator to the draw_command_barriers struct mutable simple_array<barrier_t>::iterator current_barrier_it; // Helper functions // Add a new draw command void append_draw_command(const draw_range_t& range) { current_range_index = draw_command_ranges.size(); draw_command_ranges.push_back(range); } // Insert a new draw command within the others void insert_draw_command(u32 index, const draw_range_t& range) { auto range_It = draw_command_ranges.begin(); std::advance(range_It, index); current_range_index = index; draw_command_ranges.insert(range_It, range); // Update all barrier draw ids after this one for (auto& barrier : draw_command_barriers) { if (barrier.draw_id >= index) { barrier.draw_id++; } } } public: primitive_type primitive{}; draw_command command{}; bool is_immediate_draw{}; // Set if part of the draw is submitted via push registers bool is_disjoint_primitive{}; // Set if primitive type does not rely on adjacency information bool primitive_barrier_enable{}; // Set once to signal that a primitive restart barrier can be inserted bool is_rendering{}; // Set while we're actually pushing the draw calls to host GPU simple_array<u32> inline_vertex_array{}; void operator()(utils::serial& ar); void insert_command_barrier(command_barrier_type type, u32 arg0, u32 arg1 = 0, u32 register_index = 0); /** * Optimize commands for rendering */ void compile() { // End draw call append mode current_range_index = ~0u; // TODO } /** * Insert one command range */ void append(u32 first, u32 count) { const bool barrier_enable_flag = primitive_barrier_enable; primitive_barrier_enable = false; if (!draw_command_ranges.empty()) { auto& last = draw_command_ranges[current_range_index]; if (last.count == 0) { // Special case, usually indicates an execution barrier last.first = first; last.count = count; return; } if (last.first + last.count == first) { if (!is_disjoint_primitive && barrier_enable_flag) { // Insert barrier insert_command_barrier(primitive_restart_barrier, 0); } last.count += count; return; } for (auto index = last_execution_barrier_index; index < draw_command_ranges.size(); ++index) { if (draw_command_ranges[index].first == first && draw_command_ranges[index].count == count) { // Duplicate entry. Usually this indicates a botched instancing setup. rsx_log.error("Duplicate draw request. Start=%u, Count=%u", first, count); return; } if (draw_command_ranges[index].first > first) { insert_draw_command(index, { 0, first, count }); return; } } } append_draw_command({ 0, first, count }); } /** * Returns how many vertex or index will be consumed by the draw clause. */ u32 get_elements_count() const { if (draw_command_ranges.empty()) { ensure(command == rsx::draw_command::inlined_array); return 0; } return get_range().count; } u32 min_index() const { if (draw_command_ranges.empty()) { ensure(command == rsx::draw_command::inlined_array); return 0; } return get_range().first; } bool is_single_draw() const { if (is_disjoint_primitive) return true; if (draw_command_ranges.empty()) { ensure(!inline_vertex_array.empty()); return true; } ensure(current_range_index != ~0u); for (const auto& barrier : draw_command_barriers) { if (barrier.draw_id != current_range_index) continue; if (barrier.type == primitive_restart_barrier) return false; } return true; } bool empty() const { return (command == rsx::draw_command::inlined_array) ? inline_vertex_array.empty() : draw_command_ranges.empty(); } u32 pass_count() const { if (draw_command_ranges.empty()) { ensure(!inline_vertex_array.empty()); return 1u; } u32 count = ::size32(draw_command_ranges); if (draw_command_ranges.back().count == 0) { // Dangling barrier ensure(count > 1); count--; } return count; } primitive_class classify_mode() const { return primitive >= rsx::primitive_type::triangles ? primitive_class::polygon : primitive_class::non_polygon; } void reset(rsx::primitive_type type); void begin() { current_range_index = 0; current_barrier_it = draw_command_barriers.begin(); is_rendering = true; } void end() { current_range_index = draw_command_ranges.size() - 1; } bool next() { current_range_index++; if (current_range_index >= draw_command_ranges.size()) { current_range_index = 0; is_rendering = false; return false; } if (draw_command_ranges[current_range_index].count == 0) { // Dangling execution barrier ensure(current_range_index > 0 && (current_range_index + 1) == draw_command_ranges.size()); current_range_index = 0; is_rendering = false; return false; } return true; } /** * Only call this once after the draw clause has been fully consumed to reconcile any conflicts */ void post_execute_cleanup(struct context* ctx) { ensure(current_range_index == 0); if (draw_command_ranges.size() > 1) { if (draw_command_ranges.back().count == 0) { // Dangling execution barrier current_range_index = draw_command_ranges.size() - 1; execute_pipeline_dependencies(ctx); current_range_index = 0; } } } /** * Executes commands reqiured to make the current draw state valid */ u32 execute_pipeline_dependencies(struct context* ctx) const; const draw_range_t& get_range() const { ensure(current_range_index < draw_command_ranges.size()); return draw_command_ranges[current_range_index]; } simple_array<draw_range_t> get_subranges() const { ensure(!is_single_draw()); const auto range = get_range(); const auto limit = range.first + range.count; simple_array<draw_range_t> ret; u32 previous_barrier = range.first; u32 vertex_counter = 0; for (const auto& barrier : draw_command_barriers) { if (barrier.draw_id != current_range_index) continue; if (barrier.type != primitive_restart_barrier) continue; if (barrier.address <= range.first) continue; if (barrier.address >= limit) break; const u32 count = barrier.address - previous_barrier; ret.push_back({ 0, vertex_counter, count }); previous_barrier = barrier.address; vertex_counter += count; } ensure(!ret.empty()); ensure(previous_barrier < limit); ret.push_back({ 0, vertex_counter, limit - previous_barrier }); return ret; } }; }
7,765
C++
.h
257
24.669261
117
0.647983
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,166
reg_context.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/FW/reg_context.h
#pragma once #include <util/types.hpp> namespace rsx { // TODO: Basically replaces parts of the current "rsx_state" object struct reg_context { u32 registers[1]; }; }
187
C++
.h
10
15.7
69
0.705202
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,167
draw_call.inc.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/FW/draw_call.inc.h
#pragma once #include <util/types.hpp> namespace rsx { enum class draw_command { none, array, inlined_array, indexed, }; enum command_barrier_type : u32 { primitive_restart_barrier, vertex_base_modifier_barrier, index_base_modifier_barrier, vertex_array_offset_modifier_barrier, transform_constant_load_modifier_barrier, transform_constant_update_barrier }; enum command_execution_flags : u32 { vertex_base_changed = (1 << 0), index_base_changed = (1 << 1), vertex_arrays_changed = (1 << 2), transform_constants_changed = (1 << 3) }; enum class primitive_class { polygon, non_polygon }; struct barrier_t { u32 draw_id; u64 timestamp; u32 address; u32 index; u32 arg0; u32 arg1; u32 flags; command_barrier_type type; bool operator < (const barrier_t& other) const { if (address != ~0u) { return address < other.address; } return timestamp < other.timestamp; } ENABLE_BITWISE_SERIALIZATION; }; struct draw_range_t { u32 command_data_offset = 0; u32 first = 0; u32 count = 0; ENABLE_BITWISE_SERIALIZATION; }; }
1,190
C++
.h
60
15.8
49
0.669982
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,168
GRAPH_backend.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/FW/GRAPH_backend.h
#pragma once #include "../HW/context.h" #include <span> namespace rsx { // GRAPH backend class. Wraps RSX acceleration capabilities for the host. // TODO: Flesh this out. // TODO: Replace the virtuals with something faster class GRAPH_backend { public: // virtual void begin() = 0; // virtual void end() = 0; // Patch transform constants. Units are in 32x4 units virtual void patch_transform_constants(context* /*ctx*/, u32 /*index*/, u32 /*count*/) {}; }; }
499
C++
.h
17
26
93
0.681435
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,169
nv47_sync.hpp
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/nv47_sync.hpp
#pragma once #include <util/types.hpp> #include "Emu/RSX/RSXThread.h" #include "context_accessors.define.h" namespace rsx { namespace util { template <bool FlushDMA, bool FlushPipe> static void write_gcm_label(context* ctx, u32 address, u32 data) { const bool is_flip_sema = (address == (RSX(ctx)->label_addr + 0x10) || address == (RSX(ctx)->device_addr + 0x30)); if (!is_flip_sema) { // First, queue the GPU work. If it flushes the queue for us, the following routines will be faster. const bool handled = RSX(ctx)->get_backend_config().supports_host_gpu_labels && RSX(ctx)->release_GCM_label(address, data); if (vm::_ref<RsxSemaphore>(address).val == data) { // It's a no-op to write the same value (although there is a delay in real-hw so it's more accurate to allow GPU label in this case) return; } if constexpr (FlushDMA) { // If the backend handled the request, this call will basically be a NOP g_fxo->get<rsx::dma_manager>().sync(); } if constexpr (FlushPipe) { // Manually flush the pipeline. // It is possible to stream report writes using the host GPU, but that generates too much submit traffic. RSX(ctx)->sync(); } if (handled) { // Backend will handle it, nothing to write. return; } } vm::_ref<RsxSemaphore>(address).val = data; } } } #include "context_accessors.undef.h"
1,476
C++
.h
43
28.953488
138
0.65159
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,170
nv47.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/nv47.h
// RSX Hardware definitions #pragma once #include "nv0039.h" // Buffer objects #include "nv3089.h" // Blit engine (2D) #include "nv308a.h" // Format conversion #include "nv406e.h" // Sync objects #include "nv4097.h" // 3D engine (GRAPH)
246
C++
.h
7
32.857143
41
0.704641
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,171
nv406e.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/nv406e.h
// NV47 Sync Objects #pragma once #include "context.h" namespace rsx { namespace nv406e { void set_reference(context* ctx, u32 reg, u32 arg); void semaphore_acquire(context* ctx, u32 reg, u32 arg); void semaphore_release(context* ctx, u32 reg, u32 arg); } }
287
C++
.h
12
20.5
58
0.707865
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,173
context.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/context.h
#pragma once #include <util/types.hpp> namespace rsx { class thread; struct rsx_state; #if 0 // TODO: Separate GRAPH context from RSX state struct GRAPH_context { u32 id; std::array<u32, 0x10000 / 4> registers; GRAPH_context(u32 ctx_id) : id(ctx_id) { std::fill(registers.begin(), registers.end(), 0); } }; #endif struct context { thread* rsxthr; // GRAPH_context* graph; rsx_state* register_state; }; }
471
C++
.h
26
14.538462
53
0.655172
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,174
nv3089.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/nv3089.h
// NV47 2D Blit Engine #pragma once #include "context.h" namespace rsx { namespace nv3089 { void image_in(context* ctx, u32 reg, u32 arg); } }
162
C++
.h
10
13.3
49
0.682432
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,175
nv4097.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/nv4097.h
// NV47 3D Engine #pragma once #include "common.h" #include "Emu/RSX/gcm_enums.h" #include "Emu/RSX/NV47/FW/draw_call.inc.h" #include <span> namespace rsx { enum command_barrier_type : u32; namespace nv4097 { template<typename Type> struct vertex_data_type_from_element_type; template<> struct vertex_data_type_from_element_type<float> { static const vertex_base_type type = vertex_base_type::f; }; template<> struct vertex_data_type_from_element_type<f16> { static const vertex_base_type type = vertex_base_type::sf; }; template<> struct vertex_data_type_from_element_type<u8> { static const vertex_base_type type = vertex_base_type::ub; }; template<> struct vertex_data_type_from_element_type<u16> { static const vertex_base_type type = vertex_base_type::s32k; }; template<> struct vertex_data_type_from_element_type<s16> { static const vertex_base_type type = vertex_base_type::s1; }; void clear(context* ctx, u32 reg, u32 arg); void clear_zcull(context* ctx, u32 reg, u32 arg); void set_face_property(context* ctx, u32 reg, u32 arg); void set_notify(context* ctx, u32 reg, u32 arg); void texture_read_semaphore_release(context* ctx, u32 reg, u32 arg); void back_end_write_semaphore_release(context* ctx, u32 reg, u32 arg); void set_array_element16(context* ctx, u32, u32 arg); void set_array_element32(context* ctx, u32, u32 arg); void draw_arrays(context* /*rsx*/, u32 reg, u32 arg); void draw_index_array(context* /*rsx*/, u32 reg, u32 arg); void draw_inline_array(context* /*rsx*/, u32 reg, u32 arg); void set_transform_program_start(context* ctx, u32 reg, u32); void set_vertex_attribute_output_mask(context* ctx, u32 reg, u32); void set_begin_end(context* ctxthr, u32 reg, u32 arg); void get_report(context* ctx, u32 reg, u32 arg); void clear_report_value(context* ctx, u32 reg, u32 arg); void set_render_mode(context* ctx, u32, u32 arg); void set_zcull_render_enable(context* ctx, u32, u32); void set_zcull_stats_enable(context* ctx, u32, u32); void set_zcull_pixel_count_enable(context* ctx, u32, u32); void sync(context* ctx, u32, u32); void set_shader_program_dirty(context* ctx, u32, u32); void set_surface_dirty_bit(context* ctx, u32 reg, u32 arg); void set_surface_format(context* ctx, u32 reg, u32 arg); void set_surface_options_dirty_bit(context* ctx, u32 reg, u32 arg); void set_color_mask(context* ctx, u32 reg, u32 arg); void set_stencil_op(context* ctx, u32 reg, u32 arg); void set_vertex_base_offset(context* ctx, u32 reg, u32 arg); void set_index_base_offset(context* ctx, u32 reg, u32 arg); void check_index_array_dma(context* ctx, u32 reg, u32 arg); void set_blend_equation(context* ctx, u32 reg, u32 arg); void set_blend_factor(context* ctx, u32 reg, u32 arg); void set_transform_constant_load(context* ctx, u32 reg, u32 arg); #define RSX(ctx) ctx->rsxthr #define REGS(ctx) (&rsx::method_registers) /** * id = base method register * index = register index in method * count = element count per attribute * register_count = number of registers consumed per attribute. E.g 3-element methods have padding */ template<u32 id, u32 index, int count, int register_count, typename type> void set_vertex_data_impl(context* ctx, u32 arg) { static constexpr usz increment_per_array_index = (register_count * sizeof(type)) / sizeof(u32); static constexpr usz attribute_index = index / increment_per_array_index; static constexpr usz vertex_subreg = index % increment_per_array_index; constexpr auto vtype = vertex_data_type_from_element_type<type>::type; static_assert(vtype != rsx::vertex_base_type::cmp); static_assert(vtype != rsx::vertex_base_type::ub256); // Convert LE data to BE layout if constexpr (sizeof(type) == 4) { arg = std::bit_cast<u32, be_t<u32>>(arg); } else if constexpr (sizeof(type) == 2) { // 2 16-bit values packed in 1 32-bit word const auto be_data = std::bit_cast<u32, be_t<u32>>(arg); // After u32 swap, the components are in the wrong position arg = (be_data << 16) | (be_data >> 16); } util::push_vertex_data(ctx, attribute_index, vertex_subreg, count, vtype, arg); } template<u32 index> struct set_vertex_data4ub_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { set_vertex_data_impl<NV4097_SET_VERTEX_DATA4UB_M, index, 4, 4, u8>(ctx, arg); } }; template<u32 index> struct set_vertex_data1f_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { set_vertex_data_impl<NV4097_SET_VERTEX_DATA1F_M, index, 1, 1, f32>(ctx, arg); } }; template<u32 index> struct set_vertex_data2f_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { set_vertex_data_impl<NV4097_SET_VERTEX_DATA2F_M, index, 2, 2, f32>(ctx, arg); } }; template<u32 index> struct set_vertex_data3f_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { //Register alignment is only 1, 2, or 4 (Rachet & Clank 2) set_vertex_data_impl<NV4097_SET_VERTEX_DATA3F_M, index, 3, 4, f32>(ctx, arg); } }; template<u32 index> struct set_vertex_data4f_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { set_vertex_data_impl<NV4097_SET_VERTEX_DATA4F_M, index, 4, 4, f32>(ctx, arg); } }; template<u32 index> struct set_vertex_data2s_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { set_vertex_data_impl<NV4097_SET_VERTEX_DATA2S_M, index, 2, 2, u16>(ctx, arg); } }; template<u32 index> struct set_vertex_data4s_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { set_vertex_data_impl<NV4097_SET_VERTEX_DATA4S_M, index, 4, 4, u16>(ctx, arg); } }; template<u32 index> struct set_vertex_data_scaled4s_m { static void impl(context* ctx, u32 /*reg*/, u32 arg) { set_vertex_data_impl<NV4097_SET_VERTEX_DATA_SCALED4S_M, index, 4, 4, s16>(ctx, arg); } }; struct set_transform_constant { static void impl(context* ctx, u32 reg, u32 arg); static void decode_one(context* ctx, u32 reg, u32 arg); static void batch_decode(context* ctx, u32 reg, const std::span<const u32>& args); }; struct set_transform_program { static void impl(context* ctx, u32 reg, u32 arg); }; template<u32 index> struct set_vertex_array_offset { static void impl(context* ctx, u32 reg, u32 arg) { util::push_draw_parameter_change(ctx, vertex_array_offset_modifier_barrier, reg, arg, 0, index); } }; template<u32 index> struct set_texture_dirty_bit { static void impl(context* ctx, u32 /*reg*/, u32 /*arg*/) { util::set_fragment_texture_dirty_bit(ctx, index); } }; template<u32 index> struct set_vertex_texture_dirty_bit { static void impl(context* ctx, u32 /*reg*/, u32 /*arg*/) { util::set_vertex_texture_dirty_bit(ctx, index); } }; #undef RSX #undef REGS } }
7,187
C++
.h
184
34.097826
126
0.675047
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,176
common.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/common.h
#pragma once #include <util/types.hpp> #include "context.h" #include "context_accessors.define.h" namespace rsx { enum command_barrier_type : u32; enum class vertex_base_type : u8; namespace util { u32 get_report_data_impl(rsx::context* ctx, u32 offset); void push_vertex_data(rsx::context* ctx, u32 attrib_index, u32 channel_select, int count, rsx::vertex_base_type vtype, u32 value); void push_draw_parameter_change(rsx::context* ctx, rsx::command_barrier_type type, u32 reg, u32 arg0, u32 arg1 = 0u, u32 index = 0u); void set_fragment_texture_dirty_bit(rsx::context* ctx, u32 index); void set_vertex_texture_dirty_bit(rsx::context* ctx, u32 index); } } #include "context_accessors.undef.h"
743
C++
.h
18
37.5
136
0.728814
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,177
nv308a.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/nv308a.h
// NV47 Format Conversion #pragma once #include "context.h" namespace rsx { namespace nv308a { struct color { static void impl(context* ctx, u32 reg, u32 arg); }; } }
196
C++
.h
13
11.846154
53
0.664804
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,178
context_accessors.define.h
RPCS3_rpcs3/rpcs3/Emu/RSX/NV47/HW/context_accessors.define.h
#define RSX(ctx) ctx->rsxthr #define REGS(ctx) ctx->register_state #define RSX_CAPTURE_EVENT(name) if (RSX(ctx)->capture_current_frame) { RSX(ctx)->capture_frame(name); }
174
C++
.h
3
56
104
0.725146
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,179
GunCon3.h
RPCS3_rpcs3/rpcs3/Emu/Io/GunCon3.h
#pragma once #include "Emu/Io/usb_device.h" class usb_device_guncon3 : public usb_device_emulated { public: usb_device_guncon3(u32 controller_index, const std::array<u8, 7>& location); ~usb_device_guncon3(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: u32 m_controller_index; std::array<u8, 8> m_key{}; };
521
C++
.h
13
38.307692
146
0.763889
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,180
ghltar_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/ghltar_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class ghltar_btn { w1, w2, w3, b1, b2, b3, start, hero_power, ghtv, strum_down, strum_up, dpad_left, dpad_right, whammy, tilt, count }; struct cfg_ghltar final : public emulated_pad_config<ghltar_btn> { cfg_ghltar(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<ghltar_btn> w1{ this, "W1", ghltar_btn::w1, pad_button::square }; cfg_pad_btn<ghltar_btn> w2{ this, "W2", ghltar_btn::w2, pad_button::L1 }; cfg_pad_btn<ghltar_btn> w3{ this, "W3", ghltar_btn::w3, pad_button::R1 }; cfg_pad_btn<ghltar_btn> b1{ this, "B1", ghltar_btn::b1, pad_button::cross }; cfg_pad_btn<ghltar_btn> b2{ this, "B2", ghltar_btn::b2, pad_button::circle }; cfg_pad_btn<ghltar_btn> b3{ this, "B3", ghltar_btn::b3, pad_button::triangle }; cfg_pad_btn<ghltar_btn> start{ this, "Start", ghltar_btn::start, pad_button::start }; cfg_pad_btn<ghltar_btn> hero_power{ this, "Hero Power", ghltar_btn::hero_power, pad_button::select }; cfg_pad_btn<ghltar_btn> ghtv{ this, "GHTV", ghltar_btn::ghtv, pad_button::L3 }; cfg_pad_btn<ghltar_btn> strum_down{ this, "Strum Down", ghltar_btn::strum_down, pad_button::dpad_down }; cfg_pad_btn<ghltar_btn> strum_up{ this, "Strum Up", ghltar_btn::strum_up, pad_button::dpad_up }; cfg_pad_btn<ghltar_btn> dpad_left{ this, "D-Pad Left", ghltar_btn::dpad_left, pad_button::dpad_left }; cfg_pad_btn<ghltar_btn> dpad_right{ this, "D-Pad Right", ghltar_btn::dpad_right, pad_button::dpad_right }; cfg_pad_btn<ghltar_btn> whammy{ this, "Whammy", ghltar_btn::whammy, pad_button::rs_y }; cfg_pad_btn<ghltar_btn> tilt{ this, "tilt", ghltar_btn::tilt, pad_button::rs_x }; }; struct cfg_ghltars final : public emulated_pads_config<cfg_ghltar, 2> { cfg_ghltars() : emulated_pads_config<cfg_ghltar, 2>("ghltar") {}; }; extern cfg_ghltars g_cfg_ghltar;
1,887
C++
.h
46
39.130435
107
0.698309
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,181
Turntable.h
RPCS3_rpcs3/rpcs3/Emu/Io/Turntable.h
#pragma once #include "Emu/Io/usb_device.h" class usb_device_turntable : public usb_device_emulated { public: usb_device_turntable(u32 controller_index, const std::array<u8, 7>& location); ~usb_device_turntable(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: u32 m_controller_index; };
499
C++
.h
12
39.833333
146
0.778468
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,182
Buzz.h
RPCS3_rpcs3/rpcs3/Emu/Io/Buzz.h
#pragma once #include "Emu/Io/usb_device.h" class usb_device_buzz : public usb_device_emulated { public: usb_device_buzz(u32 first_controller, u32 last_controller, const std::array<u8, 7>& location); ~usb_device_buzz(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: u32 m_first_controller; u32 m_last_controller; };
529
C++
.h
13
38.923077
146
0.773438
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,183
interception.h
RPCS3_rpcs3/rpcs3/Emu/Io/interception.h
#pragma once #include "util/atomic.hpp" namespace input { enum class active_mouse_and_keyboard : u32 { pad, emulated }; extern atomic_t<active_mouse_and_keyboard> g_active_mouse_and_keyboard; extern atomic_t<bool> g_pads_intercepted; extern atomic_t<bool> g_keyboards_intercepted; extern atomic_t<bool> g_mice_intercepted; void SetIntercepted(bool pads_intercepted, bool keyboards_intercepted, bool mice_intercepted, const char* func = __builtin_FUNCTION()); void SetIntercepted(bool all_intercepted, const char* func = __builtin_FUNCTION()); void set_mouse_and_keyboard(active_mouse_and_keyboard device); void toggle_mouse_and_keyboard(); }
662
C++
.h
18
34.666667
136
0.782473
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,184
TopShotFearmaster.h
RPCS3_rpcs3/rpcs3/Emu/Io/TopShotFearmaster.h
#pragma once #include "Emu/Io/usb_device.h" class usb_device_topshotfearmaster: public usb_device_emulated { public: usb_device_topshotfearmaster(u32 controller_index, const std::array<u8, 7>& location); ~usb_device_topshotfearmaster(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: u32 m_controller_index; u8 m_mode; };
534
C++
.h
13
39.307692
146
0.787234
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,185
recording_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/recording_config.h
#pragma once #include "Utilities/Config.h" struct cfg_recording final : cfg::node { cfg_recording(); bool load(); void save() const; struct node_video : cfg::node { node_video(cfg::node* _this) : cfg::node(_this, "Video") {} cfg::uint<0, 60> framerate{this, "Framerate", 30}; cfg::uint<0, 7680> width{this, "Width", 1280}; cfg::uint<0, 4320> height{this, "Height", 720}; cfg::uint<0, 192> pixel_format{this, "AVPixelFormat", 0}; // AVPixelFormat::AV_PIX_FMT_YUV420P cfg::uint<0, 0xFFFF> video_codec{this, "AVCodecID", 12}; // AVCodecID::AV_CODEC_ID_MPEG4 cfg::uint<0, 25000000> video_bps{this, "Video Bitrate", 4000000}; cfg::uint<0, 5> max_b_frames{this, "Max B-Frames", 2}; cfg::uint<0, 20> gop_size{this, "Group of Pictures Size", 12}; } video{ this }; struct node_audio : cfg::node { node_audio(cfg::node* _this) : cfg::node(_this, "Audio") {} cfg::uint<0x10000, 0x17000> audio_codec{this, "AVCodecID", 86018}; // AVCodecID::AV_CODEC_ID_AAC cfg::uint<0, 25000000> audio_bps{this, "Audio Bitrate", 320000}; } audio{ this }; const std::string path; }; extern cfg_recording g_cfg_recording;
1,138
C++
.h
28
38
98
0.676685
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,186
gem_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/gem_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class gem_btn { start, select, triangle, circle, cross, square, move, t, x_axis, y_axis, count }; struct cfg_gem final : public emulated_pad_config<gem_btn> { cfg_gem(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<gem_btn> start{ this, "Start", gem_btn::start, pad_button::start }; cfg_pad_btn<gem_btn> select{ this, "Select", gem_btn::select, pad_button::select }; cfg_pad_btn<gem_btn> triangle{ this, "Triangle", gem_btn::triangle, pad_button::triangle }; cfg_pad_btn<gem_btn> circle{ this, "Circle", gem_btn::circle, pad_button::circle }; cfg_pad_btn<gem_btn> cross{ this, "Cross", gem_btn::cross, pad_button::cross }; cfg_pad_btn<gem_btn> square{ this, "Square", gem_btn::square, pad_button::square }; cfg_pad_btn<gem_btn> move{ this, "Move", gem_btn::move, pad_button::R1 }; cfg_pad_btn<gem_btn> t{ this, "T", gem_btn::t, pad_button::R2 }; cfg_pad_btn<gem_btn> x_axis{ this, "X-Axis", gem_btn::x_axis, pad_button::ls_x }; cfg_pad_btn<gem_btn> y_axis{ this, "Y-Axis", gem_btn::y_axis, pad_button::ls_y }; }; struct cfg_gems final : public emulated_pads_config<cfg_gem, 4> { cfg_gems() : emulated_pads_config<cfg_gem, 4>("gem") {}; }; extern cfg_gems g_cfg_gem;
1,305
C++
.h
36
34.388889
92
0.686757
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,187
usb_vfs.h
RPCS3_rpcs3/rpcs3/Emu/Io/usb_vfs.h
#pragma once #include "Emu/Io/usb_device.h" #include "Utilities/Config.h" class usb_device_vfs : public usb_device_emulated { public: usb_device_vfs(const cfg::device_info& device_info, const std::array<u8, 7>& location); ~usb_device_vfs(); };
248
C++
.h
9
26.111111
88
0.746835
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,188
pad_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/pad_config.h
#pragma once #include "pad_types.h" #include "Utilities/Config.h" #include <array> namespace pad { constexpr static std::string_view keyboard_device_name = "Keyboard"; } struct cfg_sensor final : cfg::node { cfg_sensor(node* owner, const std::string& name) : cfg::node(owner, name) {} cfg::string axis{ this, "Axis", "" }; cfg::_bool mirrored{ this, "Mirrored", false }; cfg::_int<-1023, 1023> shift{ this, "Shift", 0 }; }; struct cfg_pad final : cfg::node { cfg_pad() {}; cfg_pad(node* owner, const std::string& name) : cfg::node(owner, name) {} static std::vector<std::string> get_buttons(const std::string& str); static std::string get_buttons(std::vector<std::string> vec); cfg::string ls_left{ this, "Left Stick Left", "" }; cfg::string ls_down{ this, "Left Stick Down", "" }; cfg::string ls_right{ this, "Left Stick Right", "" }; cfg::string ls_up{ this, "Left Stick Up", "" }; cfg::string rs_left{ this, "Right Stick Left", "" }; cfg::string rs_down{ this, "Right Stick Down", "" }; cfg::string rs_right{ this, "Right Stick Right", "" }; cfg::string rs_up{ this, "Right Stick Up", "" }; cfg::string start{ this, "Start", "" }; cfg::string select{ this, "Select", "" }; cfg::string ps{ this, "PS Button", "" }; cfg::string square{ this, "Square", "" }; cfg::string cross{ this, "Cross", "" }; cfg::string circle{ this, "Circle", "" }; cfg::string triangle{ this, "Triangle", "" }; cfg::string left{ this, "Left", "" }; cfg::string down{ this, "Down", "" }; cfg::string right{ this, "Right", "" }; cfg::string up{ this, "Up", "" }; cfg::string r1{ this, "R1", "" }; cfg::string r2{ this, "R2", "" }; cfg::string r3{ this, "R3", "" }; cfg::string l1{ this, "L1", "" }; cfg::string l2{ this, "L2", "" }; cfg::string l3{ this, "L3", "" }; cfg::string ir_nose{ this, "IR Nose", "" }; cfg::string ir_tail{ this, "IR Tail", "" }; cfg::string ir_left{ this, "IR Left", "" }; cfg::string ir_right{ this, "IR Right", "" }; cfg::string tilt_left{ this, "Tilt Left", "" }; cfg::string tilt_right{ this, "Tilt Right", "" }; cfg_sensor motion_sensor_x{ this, "Motion Sensor X" }; cfg_sensor motion_sensor_y{ this, "Motion Sensor Y" }; cfg_sensor motion_sensor_z{ this, "Motion Sensor Z" }; cfg_sensor motion_sensor_g{ this, "Motion Sensor G" }; cfg::string pressure_intensity_button{ this, "Pressure Intensity Button", "" }; cfg::uint<0, 100> pressure_intensity{ this, "Pressure Intensity Percent", 50 }; cfg::_bool pressure_intensity_toggle_mode{ this, "Pressure Intensity Toggle Mode", false }; cfg::uint<0, 255> pressure_intensity_deadzone{ this, "Pressure Intensity Deadzone", 0 }; cfg::string analog_limiter_button{ this, "Analog Limiter Button", "" }; cfg::_bool analog_limiter_toggle_mode{ this, "Analog Limiter Toggle Mode", false }; cfg::uint<0, 200> lstickmultiplier{ this, "Left Stick Multiplier", 100 }; cfg::uint<0, 200> rstickmultiplier{ this, "Right Stick Multiplier", 100 }; cfg::uint<0, 1000000> lstickdeadzone{ this, "Left Stick Deadzone", 0 }; cfg::uint<0, 1000000> rstickdeadzone{ this, "Right Stick Deadzone", 0 }; cfg::uint<0, 1000000> lstick_anti_deadzone{ this, "Left Stick Anti-Deadzone", 0 }; cfg::uint<0, 1000000> rstick_anti_deadzone{ this, "Right Stick Anti-Deadzone", 0 }; cfg::uint<0, 1000000> ltriggerthreshold{ this, "Left Trigger Threshold", 0 }; cfg::uint<0, 1000000> rtriggerthreshold{ this, "Right Trigger Threshold", 0 }; cfg::uint<0, 1000000> lpadsquircling{ this, "Left Pad Squircling Factor", 8000 }; cfg::uint<0, 1000000> rpadsquircling{ this, "Right Pad Squircling Factor", 8000 }; cfg::uint<0, 255> colorR{ this, "Color Value R", 0 }; cfg::uint<0, 255> colorG{ this, "Color Value G", 0 }; cfg::uint<0, 255> colorB{ this, "Color Value B", 0 }; cfg::_bool led_low_battery_blink{ this, "Blink LED when battery is below 20%", true }; cfg::_bool led_battery_indicator{ this, "Use LED as a battery indicator", false }; cfg::uint<0, 100> led_battery_indicator_brightness{ this, "LED battery indicator brightness", 50 }; cfg::_bool player_led_enabled{ this, "Player LED enabled", true }; cfg::_bool enable_vibration_motor_large{ this, "Enable Large Vibration Motor", true }; cfg::_bool enable_vibration_motor_small{ this, "Enable Small Vibration Motor", true }; cfg::_bool switch_vibration_motors{ this, "Switch Vibration Motors", false }; cfg::_enum<mouse_movement_mode> mouse_move_mode{ this, "Mouse Movement Mode", mouse_movement_mode::relative }; cfg::uint<0, 255> mouse_deadzone_x{ this, "Mouse Deadzone X Axis", 60 }; cfg::uint<0, 255> mouse_deadzone_y{ this, "Mouse Deadzone Y Axis", 60 }; cfg::uint<0, 999999> mouse_acceleration_x{ this, "Mouse Acceleration X Axis", 200 }; cfg::uint<0, 999999> mouse_acceleration_y{ this, "Mouse Acceleration Y Axis", 250 }; cfg::uint<0, 100> l_stick_lerp_factor{ this, "Left Stick Lerp Factor", 100 }; cfg::uint<0, 100> r_stick_lerp_factor{ this, "Right Stick Lerp Factor", 100 }; cfg::uint<0, 100> analog_lerp_factor{ this, "Analog Button Lerp Factor", 100 }; cfg::uint<0, 100> trigger_lerp_factor{ this, "Trigger Lerp Factor", 100 }; cfg::uint<CELL_PAD_PCLASS_TYPE_STANDARD, CELL_PAD_PCLASS_TYPE_MAX> device_class_type{ this, "Device Class Type", 0 }; cfg::uint<0, 65535> vendor_id{ this, "Vendor ID", 0 }; cfg::uint<0, 65535> product_id{ this, "Product ID", 0 }; }; struct cfg_player final : cfg::node { pad_handler def_handler = pad_handler::null; cfg_player(node* owner, const std::string& name, pad_handler type) : cfg::node(owner, name), def_handler(type) {} cfg::_enum<pad_handler> handler{ this, "Handler", def_handler }; cfg::string device{ this, "Device", handler.to_string() }; cfg_pad config{ this, "Config" }; cfg::string buddy_device{ this, "Buddy Device", handler.to_string() }; }; struct cfg_input final : cfg::node { cfg_player player1{ this, "Player 1 Input", pad_handler::null }; cfg_player player2{ this, "Player 2 Input", pad_handler::null }; cfg_player player3{ this, "Player 3 Input", pad_handler::null }; cfg_player player4{ this, "Player 4 Input", pad_handler::null }; cfg_player player5{ this, "Player 5 Input", pad_handler::null }; cfg_player player6{ this, "Player 6 Input", pad_handler::null }; cfg_player player7{ this, "Player 7 Input", pad_handler::null }; std::array<cfg_player*, 7> player{ &player1, &player2, &player3, &player4, &player5, &player6, &player7 }; // Thanks gcc! bool load(const std::string& title_id = "", const std::string& profile = "", bool strict = false); void save(const std::string& title_id, const std::string& profile = "") const; }; struct cfg_input_configurations final : cfg::node { cfg_input_configurations(); bool load(); void save() const; const std::string path; const std::string global_key = "global"; const std::string default_config = "Default"; cfg::map_entry active_configs{ this, "Active Configurations" }; }; extern cfg_input g_cfg_input; extern cfg_input_configurations g_cfg_input_configs;
6,972
C++
.h
129
52
122
0.683693
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,189
Dimensions.h
RPCS3_rpcs3/rpcs3/Emu/Io/Dimensions.h
#pragma once #include "Emu/Io/usb_device.h" #include "Utilities/mutex.h" #include <array> #include <optional> #include <queue> static constexpr size_t dimensions_figure_count = 7; struct dimensions_figure { fs::file dim_file; std::array<u8, 0x2D * 0x04> data{}; u8 index = 255; u8 pad = 255; u32 id = 0; void save(); }; class dimensions_toypad { public: static void get_blank_response(u8 type, u8 sequence, std::array<u8, 32>& reply_buf); void generate_random_number(const u8* buf, u8 sequence, std::array<u8, 32>& reply_buf); void initialize_rng(u32 seed); void get_challenge_response(const u8* buf, u8 sequence, std::array<u8, 32>& reply_buf); void query_block(u8 index, u8 page, std::array<u8, 32>& reply_buf, u8 sequence); void write_block(u8 index, u8 page, const u8* to_write_buf, std::array<u8, 32>& reply_buf, u8 sequence); void get_model(const u8* buf, u8 sequence, std::array<u8, 32>& reply_buf); std::optional<std::array<u8, 32>> pop_added_removed_response(); bool remove_figure(u8 pad, u8 index, bool full_remove, bool lock); bool temp_remove(u8 index); bool cancel_remove(u8 index); u32 load_figure(const std::array<u8, 0x2D * 0x04>& buf, fs::file in_file, u8 pad, u8 index, bool lock); bool move_figure(u8 pad, u8 index, u8 old_pad, u8 old_index); static bool create_blank_character(std::array<u8, 0x2D * 0x04>& buf, u16 id); protected: shared_mutex m_dimensions_mutex; std::array<dimensions_figure, dimensions_figure_count> m_figures{}; private: static void random_uid(u8* uid_buffer); static u8 generate_checksum(const std::array<u8, 32>& data, u32 num_of_bytes); static std::array<u8, 8> decrypt(const u8* buf, std::optional<std::array<u8, 16>> key); static std::array<u8, 8> encrypt(const u8* buf, std::optional<std::array<u8, 16>> key); static std::array<u8, 16> generate_figure_key(const std::array<u8, 0x2D * 0x04>& buf); static u32 scramble(const std::array<u8, 7>& uid, u8 count); static std::array<u8, 4> pwd_generate(const std::array<u8, 7>& uid); static std::array<u8, 4> dimensions_randomize(const std::vector<u8> key, u8 count); static u32 get_figure_id(const std::array<u8, 0x2D * 0x04>& buf); u32 get_next(); dimensions_figure& get_figure_by_index(u8 index); u32 m_random_a{}; u32 m_random_b{}; u32 m_random_c{}; u32 m_random_d{}; u8 m_figure_order = 0; std::queue<std::array<u8, 32>> m_figure_added_removed_responses; }; extern dimensions_toypad g_dimensionstoypad; class usb_device_dimensions : public usb_device_emulated { public: usb_device_dimensions(const std::array<u8, 7>& location); ~usb_device_dimensions(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; void isochronous_transfer(UsbTransfer* transfer) override; protected: shared_mutex m_query_mutex; std::queue<std::array<u8, 32>> m_queries; };
2,990
C++
.h
68
42.102941
146
0.731867
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,190
usio.h
RPCS3_rpcs3/rpcs3/Emu/Io/usio.h
#pragma once #include "Emu/system_utils.hpp" #include "Emu/Io/usb_device.h" class usb_device_usio : public usb_device_emulated { public: usb_device_usio(const std::array<u8, 7>& location); ~usb_device_usio(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: void load_backup(); void save_backup(); void translate_input_taiko(); void translate_input_tekken(); void usio_write(u8 channel, u16 reg, std::vector<u8>& data); void usio_read(u8 channel, u16 reg, u16 size); void usio_init(u8 channel, u16 reg, u16 size); private: bool is_used = false; const std::string usio_backup_path = rpcs3::utils::get_hdd1_dir() + "/caches/usiobackup.bin"; std::vector<u8> response; struct io_status { bool test_on = false; bool test_key_pressed = false; bool coin_key_pressed = false; le_t<u16> coin_counter = 0; }; std::array<io_status, 2> m_io_status; };
1,073
C++
.h
31
32.548387
146
0.735266
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,191
TopShotElite.h
RPCS3_rpcs3/rpcs3/Emu/Io/TopShotElite.h
#pragma once #include "Emu/Io/usb_device.h" class usb_device_topshotelite : public usb_device_emulated { public: usb_device_topshotelite(u32 controller_index, const std::array<u8, 7>& location); ~usb_device_topshotelite(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: u32 m_controller_index; u8 m_mode; };
520
C++
.h
13
38.230769
146
0.779324
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,192
pad_types.h
RPCS3_rpcs3/rpcs3/Emu/Io/pad_types.h
#pragma once #include "util/types.hpp" #include "util/endian.hpp" #include "Emu/Io/pad_config_types.h" #include <map> #include <set> #include <vector> enum class pad_button : u8 { dpad_up = 0, dpad_down, dpad_left, dpad_right, select, start, ps, triangle, circle, square, cross, L1, R1, L2, R2, L3, R3, ls_up, ls_down, ls_left, ls_right, ls_x, ls_y, rs_up, rs_down, rs_left, rs_right, rs_x, rs_y, pad_button_max_enum, // Special buttons for mouse input mouse_button_1, mouse_button_2, mouse_button_3, mouse_button_4, mouse_button_5, mouse_button_6, mouse_button_7, mouse_button_8, }; u32 pad_button_offset(pad_button button); u32 pad_button_keycode(pad_button button); enum class axis_direction : u8 { both = 0, negative, positive }; u32 get_axis_keycode(u32 offset, u16 value); enum SystemInfo { CELL_PAD_INFO_INTERCEPTED = 0x00000001 }; enum PortStatus { CELL_PAD_STATUS_DISCONNECTED = 0x00000000, CELL_PAD_STATUS_CONNECTED = 0x00000001, CELL_PAD_STATUS_ASSIGN_CHANGES = 0x00000002, CELL_PAD_STATUS_CUSTOM_CONTROLLER = 0x00000004, }; enum PortSettings { CELL_PAD_SETTING_LDD = 0x00000001, // Speculative CELL_PAD_SETTING_PRESS_ON = 0x00000002, CELL_PAD_SETTING_SENSOR_ON = 0x00000004, CELL_PAD_SETTING_PRESS_OFF = 0x00000000, CELL_PAD_SETTING_SENSOR_OFF = 0x00000000, }; enum Digital1Flags : u32 { CELL_PAD_CTRL_SELECT = 0x00000001, CELL_PAD_CTRL_L3 = 0x00000002, CELL_PAD_CTRL_R3 = 0x00000004, CELL_PAD_CTRL_START = 0x00000008, CELL_PAD_CTRL_UP = 0x00000010, CELL_PAD_CTRL_RIGHT = 0x00000020, CELL_PAD_CTRL_DOWN = 0x00000040, CELL_PAD_CTRL_LEFT = 0x00000080, CELL_PAD_CTRL_PS = 0x00000100, }; enum Digital2Flags : u32 { CELL_PAD_CTRL_L2 = 0x00000001, CELL_PAD_CTRL_R2 = 0x00000002, CELL_PAD_CTRL_L1 = 0x00000004, CELL_PAD_CTRL_R1 = 0x00000008, CELL_PAD_CTRL_TRIANGLE = 0x00000010, CELL_PAD_CTRL_CIRCLE = 0x00000020, CELL_PAD_CTRL_CROSS = 0x00000040, CELL_PAD_CTRL_SQUARE = 0x00000080, }; enum { CELL_PAD_CTRL_LDD_PS = 0x00000001 }; enum DeviceCapability { CELL_PAD_CAPABILITY_PS3_CONFORMITY = 0x00000001, // PS3 Conformity Controller CELL_PAD_CAPABILITY_PRESS_MODE = 0x00000002, // Press mode supported CELL_PAD_CAPABILITY_SENSOR_MODE = 0x00000004, // Sensor mode supported CELL_PAD_CAPABILITY_HP_ANALOG_STICK = 0x00000008, // High Precision analog stick CELL_PAD_CAPABILITY_ACTUATOR = 0x00000010, // Motor supported }; enum DeviceType { CELL_PAD_DEV_TYPE_STANDARD = 0, CELL_PAD_DEV_TYPE_BD_REMOCON = 4, CELL_PAD_DEV_TYPE_LDD = 5, }; // Controller types enum { CELL_PAD_PCLASS_TYPE_STANDARD = 0x00, CELL_PAD_PCLASS_TYPE_GUITAR = 0x01, CELL_PAD_PCLASS_TYPE_DRUM = 0x02, CELL_PAD_PCLASS_TYPE_DJ = 0x03, CELL_PAD_PCLASS_TYPE_DANCEMAT = 0x04, CELL_PAD_PCLASS_TYPE_NAVIGATION = 0x05, CELL_PAD_PCLASS_TYPE_SKATEBOARD = 0x8001, // these are used together with pad->is_fake_pad to capture input events for usbd/gem/move without conflicting with cellPad CELL_PAD_FAKE_TYPE_FIRST = 0xa000, CELL_PAD_FAKE_TYPE_GUNCON3 = 0xa000, CELL_PAD_FAKE_TYPE_TOP_SHOT_ELITE = 0xa001, CELL_PAD_FAKE_TYPE_TOP_SHOT_FEARMASTER = 0xa002, CELL_PAD_FAKE_TYPE_GAMETABLET = 0xa003, CELL_PAD_FAKE_TYPE_LAST, CELL_PAD_PCLASS_TYPE_MAX // last item }; // Profile of a Standard Type Controller // Profile of a Navigation Type Controller // Bits 0 – 31 All 0s // Profile of a Guitar Type Controller enum { // Basic CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_1 = 0x00000001, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_2 = 0x00000002, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_3 = 0x00000004, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_4 = 0x00000008, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_5 = 0x00000010, CELL_PAD_PCLASS_PROFILE_GUITAR_STRUM_UP = 0x00000020, CELL_PAD_PCLASS_PROFILE_GUITAR_STRUM_DOWN = 0x00000040, CELL_PAD_PCLASS_PROFILE_GUITAR_WHAMMYBAR = 0x00000080, // All Basic = 0x000000FF // Optional CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_H1 = 0x00000100, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_H2 = 0x00000200, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_H3 = 0x00000400, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_H4 = 0x00000800, CELL_PAD_PCLASS_PROFILE_GUITAR_FRET_H5 = 0x00001000, CELL_PAD_PCLASS_PROFILE_GUITAR_5WAY_EFFECT = 0x00002000, CELL_PAD_PCLASS_PROFILE_GUITAR_TILT_SENS = 0x00004000, // All = 0x00007FFF }; // Profile of a Drum Type Controller enum { CELL_PAD_PCLASS_PROFILE_DRUM_SNARE = 0x00000001, CELL_PAD_PCLASS_PROFILE_DRUM_TOM = 0x00000002, CELL_PAD_PCLASS_PROFILE_DRUM_TOM2 = 0x00000004, CELL_PAD_PCLASS_PROFILE_DRUM_TOM_FLOOR = 0x00000008, CELL_PAD_PCLASS_PROFILE_DRUM_KICK = 0x00000010, CELL_PAD_PCLASS_PROFILE_DRUM_CYM_HiHAT = 0x00000020, CELL_PAD_PCLASS_PROFILE_DRUM_CYM_CRASH = 0x00000040, CELL_PAD_PCLASS_PROFILE_DRUM_CYM_RIDE = 0x00000080, CELL_PAD_PCLASS_PROFILE_DRUM_KICK2 = 0x00000100, // All = 0x000001FF }; // Profile of a DJ Deck Type Controller enum { CELL_PAD_PCLASS_PROFILE_DJ_MIXER_ATTACK = 0x00000001, CELL_PAD_PCLASS_PROFILE_DJ_MIXER_CROSSFADER = 0x00000002, CELL_PAD_PCLASS_PROFILE_DJ_MIXER_DSP_DIAL = 0x00000004, CELL_PAD_PCLASS_PROFILE_DJ_DECK1_STREAM1 = 0x00000008, CELL_PAD_PCLASS_PROFILE_DJ_DECK1_STREAM2 = 0x00000010, CELL_PAD_PCLASS_PROFILE_DJ_DECK1_STREAM3 = 0x00000020, CELL_PAD_PCLASS_PROFILE_DJ_DECK1_PLATTER = 0x00000040, CELL_PAD_PCLASS_PROFILE_DJ_DECK2_STREAM1 = 0x00000080, CELL_PAD_PCLASS_PROFILE_DJ_DECK2_STREAM2 = 0x00000100, CELL_PAD_PCLASS_PROFILE_DJ_DECK2_STREAM3 = 0x00000200, CELL_PAD_PCLASS_PROFILE_DJ_DECK2_PLATTER = 0x00000400, // All = 0x000007FF }; // Profile of a Dance Mat Type Controller enum { CELL_PAD_PCLASS_PROFILE_DANCEMAT_CIRCLE = 0x00000001, CELL_PAD_PCLASS_PROFILE_DANCEMAT_CROSS = 0x00000002, CELL_PAD_PCLASS_PROFILE_DANCEMAT_TRIANGLE = 0x00000004, CELL_PAD_PCLASS_PROFILE_DANCEMAT_SQUARE = 0x00000008, CELL_PAD_PCLASS_PROFILE_DANCEMAT_RIGHT = 0x00000010, CELL_PAD_PCLASS_PROFILE_DANCEMAT_LEFT = 0x00000020, CELL_PAD_PCLASS_PROFILE_DANCEMAT_UP = 0x00000040, CELL_PAD_PCLASS_PROFILE_DANCEMAT_DOWN = 0x00000080, // All = 0x000000FF }; enum ButtonDataOffset { CELL_PAD_BTN_OFFSET_DIGITAL1 = 2, CELL_PAD_BTN_OFFSET_DIGITAL2 = 3, CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X = 4, CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y = 5, CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X = 6, CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y = 7, CELL_PAD_BTN_OFFSET_PRESS_RIGHT = 8, CELL_PAD_BTN_OFFSET_PRESS_LEFT = 9, CELL_PAD_BTN_OFFSET_PRESS_UP = 10, CELL_PAD_BTN_OFFSET_PRESS_DOWN = 11, CELL_PAD_BTN_OFFSET_PRESS_TRIANGLE = 12, CELL_PAD_BTN_OFFSET_PRESS_CIRCLE = 13, CELL_PAD_BTN_OFFSET_PRESS_CROSS = 14, CELL_PAD_BTN_OFFSET_PRESS_SQUARE = 15, CELL_PAD_BTN_OFFSET_PRESS_L1 = 16, CELL_PAD_BTN_OFFSET_PRESS_R1 = 17, CELL_PAD_BTN_OFFSET_PRESS_L2 = 18, CELL_PAD_BTN_OFFSET_PRESS_R2 = 19, CELL_PAD_BTN_OFFSET_SENSOR_X = 20, CELL_PAD_BTN_OFFSET_SENSOR_Y = 21, CELL_PAD_BTN_OFFSET_SENSOR_Z = 22, CELL_PAD_BTN_OFFSET_SENSOR_G = 23, // Fake helpers CELL_PAD_BTN_OFFSET_PRESS_PIGGYBACK, }; enum CellPadPeriphGuitarBtnDataOffset { // Basic CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_1 = 24, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_2 = 25, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_3 = 26, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_4 = 27, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_5 = 28, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_STRUM_UP = 29, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_STRUM_DOWN = 30, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_WHAMMYBAR = 31, // 128-255 // Optional CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H1 = 32, // ROCKBAND Stratocaster CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H2 = 33, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H3 = 34, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H4 = 35, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H5 = 36, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_5WAY_EFFECT = 37, CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_TILT_SENS = 38, }; enum CellPadPeriphDrumBtnDataOffset { CELL_PAD_PCLASS_BTN_OFFSET_DRUM_SNARE = 24, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_TOM = 25, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_TOM2 = 26, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_TOM_FLOOR = 27, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_KICK = 28, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_CYM_HiHAT = 29, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_CYM_CRASH = 30, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_CYM_RIDE = 31, CELL_PAD_PCLASS_BTN_OFFSET_DRUM_KICK2 = 32, }; enum CellPadPeriphDJBtnDataOffset { CELL_PAD_PCLASS_BTN_OFFSET_DJ_MIXER_ATTACK = 24, CELL_PAD_PCLASS_BTN_OFFSET_DJ_MIXER_CROSSFADER = 25, CELL_PAD_PCLASS_BTN_OFFSET_DJ_MIXER_DSP_DIAL = 26, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_STREAM1 = 27, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_STREAM2 = 28, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_STREAM3 = 29, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_PLATTER = 30, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_STREAM1 = 31, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_STREAM2 = 32, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_STREAM3 = 33, CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_PLATTER = 34, }; enum CellPadPeriphDanceMatBtnDataOffset { CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_CIRCLE = 24, CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_CROSS = 25, CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_TRIANGLE = 26, CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_SQUARE = 27, CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_RIGHT = 28, CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_LEFT = 29, CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_UP = 30, CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_DOWN = 31, }; enum { CELL_PAD_ACTUATOR_MAX = 2, CELL_PAD_MAX_PORT_NUM = 7, CELL_PAD_MAX_CAPABILITY_INFO = 32, CELL_PAD_MAX_CODES = 64, CELL_MAX_PADS = 127, }; struct CellPadData { be_t<s32> len; be_t<u16> button[CELL_PAD_MAX_CODES]; }; static constexpr u16 DEFAULT_MOTION_X = 512; static constexpr u16 DEFAULT_MOTION_Y = 399; static constexpr u16 DEFAULT_MOTION_Z = 512; static constexpr u16 DEFAULT_MOTION_G = 512; // Fake helper enum enum PressurePiggybackFlags : u32 { CELL_PAD_CTRL_PRESS_RIGHT = CELL_PAD_BTN_OFFSET_PRESS_RIGHT, CELL_PAD_CTRL_PRESS_LEFT = CELL_PAD_BTN_OFFSET_PRESS_LEFT, CELL_PAD_CTRL_PRESS_UP = CELL_PAD_BTN_OFFSET_PRESS_UP, CELL_PAD_CTRL_PRESS_DOWN = CELL_PAD_BTN_OFFSET_PRESS_DOWN, CELL_PAD_CTRL_PRESS_TRIANGLE = CELL_PAD_BTN_OFFSET_PRESS_TRIANGLE, CELL_PAD_CTRL_PRESS_CIRCLE = CELL_PAD_BTN_OFFSET_PRESS_CIRCLE, CELL_PAD_CTRL_PRESS_CROSS = CELL_PAD_BTN_OFFSET_PRESS_CROSS, CELL_PAD_CTRL_PRESS_SQUARE = CELL_PAD_BTN_OFFSET_PRESS_SQUARE, CELL_PAD_CTRL_PRESS_L1 = CELL_PAD_BTN_OFFSET_PRESS_L1, CELL_PAD_CTRL_PRESS_R1 = CELL_PAD_BTN_OFFSET_PRESS_R1, CELL_PAD_CTRL_PRESS_L2 = CELL_PAD_BTN_OFFSET_PRESS_L2, CELL_PAD_CTRL_PRESS_R2 = CELL_PAD_BTN_OFFSET_PRESS_R2, }; constexpr u32 special_button_offset = 666; // Must not conflict with other CELL offsets like ButtonDataOffset enum special_button_value { pressure_intensity, analog_limiter }; struct Button { u32 m_offset = 0; std::set<u32> m_key_codes{}; u32 m_outKeyCode = 0; u16 m_value = 0; bool m_pressed = false; u16 m_actual_value = 0; // only used in keyboard_pad_handler bool m_analog = false; // only used in keyboard_pad_handler bool m_trigger = false; // only used in keyboard_pad_handler std::map<u32, u16> m_pressed_keys{}; // only used in keyboard_pad_handler Button(u32 offset, std::set<u32> key_codes, u32 outKeyCode) : m_offset(offset) , m_key_codes(std::move(key_codes)) , m_outKeyCode(outKeyCode) { if (offset == CELL_PAD_BTN_OFFSET_DIGITAL1) { if (outKeyCode == CELL_PAD_CTRL_LEFT || outKeyCode == CELL_PAD_CTRL_RIGHT || outKeyCode == CELL_PAD_CTRL_UP || outKeyCode == CELL_PAD_CTRL_DOWN) { m_analog = true; } } else if (offset == CELL_PAD_BTN_OFFSET_DIGITAL2) { if (outKeyCode == CELL_PAD_CTRL_CROSS || outKeyCode == CELL_PAD_CTRL_CIRCLE || outKeyCode == CELL_PAD_CTRL_SQUARE || outKeyCode == CELL_PAD_CTRL_TRIANGLE || outKeyCode == CELL_PAD_CTRL_L1 || outKeyCode == CELL_PAD_CTRL_R1) { m_analog = true; } else if (outKeyCode == CELL_PAD_CTRL_L2 || outKeyCode == CELL_PAD_CTRL_R2) { m_trigger = true; } } } }; struct AnalogStick { u32 m_offset = 0; std::set<u32> m_key_codes_min{}; std::set<u32> m_key_codes_max{}; u16 m_value = 128; std::map<u32, u16> m_pressed_keys_min{}; // only used in keyboard_pad_handler std::map<u32, u16> m_pressed_keys_max{}; // only used in keyboard_pad_handler AnalogStick() {} AnalogStick(u32 offset, std::set<u32> key_codes_min, std::set<u32> key_codes_max) : m_offset(offset) , m_key_codes_min(std::move(key_codes_min)) , m_key_codes_max(std::move(key_codes_max)) {} }; struct AnalogSensor { u32 m_offset = 0; u32 m_keyCode = 0; b8 m_mirrored = false; s16 m_shift = 0; u16 m_value = 0; AnalogSensor() {} AnalogSensor(u32 offset, u32 key_code, b8 mirrored, s16 shift, u16 value) : m_offset(offset) , m_keyCode(key_code) , m_mirrored(mirrored) , m_shift(shift) , m_value(value) {} }; struct VibrateMotor { bool m_is_large_motor = false; u8 m_value = 0; VibrateMotor() {} VibrateMotor(bool is_large_motor, u8 value) : m_is_large_motor(is_large_motor) , m_value(value) {} }; struct Pad { const pad_handler m_pad_handler; const u32 m_player_id; bool m_buffer_cleared{true}; u32 m_port_status{0}; u32 m_device_capability{0}; u32 m_device_type{0}; u32 m_class_type{0}; u32 m_class_profile{0}; u16 m_vendor_id{0}; u16 m_product_id{0}; s32 m_pressure_intensity_button_index{-1}; // Special button index. -1 if not set. bool m_pressure_intensity_button_pressed{}; // Last sensitivity button press state, used for toggle. bool m_pressure_intensity_toggled{}; // Whether the sensitivity is toggled on or off. u8 m_pressure_intensity{127}; // 0-255 bool m_adjust_pressure_last{}; // only used in keyboard_pad_handler bool get_pressure_intensity_button_active(bool is_toggle_mode, u32 player_id); s32 m_analog_limiter_button_index{-1}; // Special button index. -1 if not set. bool m_analog_limiter_button_pressed{}; // Last sensitivity button press state, used for toggle. bool m_analog_limiter_toggled{}; // Whether the sensitivity is toggled on or off. bool m_analog_limiter_enabled_last{}; // only used in keyboard_pad_handler bool get_analog_limiter_button_active(bool is_toggle_mode, u32 player_id); // Cable State: 0 - 1 plugged in ? u8 m_cable_state{0}; // DS4: 0 - 9 while unplugged, 0 - 10 while plugged in, 11 charge complete // XInput: 0 = Empty, 1 = Low, 2 = Medium, 3 = Full u8 m_battery_level{0}; std::vector<Button> m_buttons; std::array<AnalogStick, 4> m_sticks{}; std::array<AnalogSensor, 4> m_sensors{}; std::array<VibrateMotor, 2> m_vibrateMotors{}; // These hold bits for their respective buttons u16 m_digital_1{0}; u16 m_digital_2{0}; // All sensors go from 0-255 u16 m_analog_left_x{128}; u16 m_analog_left_y{128}; u16 m_analog_right_x{128}; u16 m_analog_right_y{128}; u16 m_press_right{0}; u16 m_press_left{0}; u16 m_press_up{0}; u16 m_press_down{0}; u16 m_press_triangle{0}; u16 m_press_circle{0}; u16 m_press_cross{0}; u16 m_press_square{0}; u16 m_press_L1{0}; u16 m_press_L2{0}; u16 m_press_R1{0}; u16 m_press_R2{0}; // Except for these...0-1023 // ~399 on sensor y is a level non moving controller u16 m_sensor_x{DEFAULT_MOTION_X}; u16 m_sensor_y{DEFAULT_MOTION_Y}; u16 m_sensor_z{DEFAULT_MOTION_Z}; u16 m_sensor_g{DEFAULT_MOTION_G}; bool ldd{false}; CellPadData ldd_data{}; bool is_fake_pad = false; explicit Pad(pad_handler handler, u32 player_id, u32 port_status, u32 device_capability, u32 device_type) : m_pad_handler(handler) , m_player_id(player_id) , m_port_status(port_status) , m_device_capability(device_capability) , m_device_type(device_type) { } void Init(u32 port_status, u32 device_capability, u32 device_type, u32 class_type, u32 class_profile, u16 vendor_id, u16 product_id, u8 pressure_intensity_percent) { m_port_status = port_status; m_device_capability = device_capability; m_device_type = device_type; m_class_type = class_type; m_class_profile = class_profile; m_vendor_id = vendor_id; m_product_id = product_id; m_pressure_intensity = (255 * pressure_intensity_percent) / 100; } };
16,616
C++
.h
488
32.010246
193
0.714126
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,193
emulated_pad_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/emulated_pad_config.h
#pragma once #include "Utilities/Config.h" #include "Utilities/mutex.h" #include "pad_types.h" #include "MouseHandler.h" #include <array> #include <map> #include <set> #include <vector> LOG_CHANNEL(cfg_log, "CFG"); template <typename T> class cfg_pad_btn : public cfg::_enum<pad_button> { public: cfg_pad_btn(cfg::node* owner, const std::string& name, T id, pad_button value, bool dynamic = false) : cfg::_enum<pad_button>(owner, name, value, dynamic) , m_btn_id(id) {}; T btn_id() const { return m_btn_id; } private: T m_btn_id; }; template <typename T> struct emulated_pad_config : cfg::node { public: using cfg::node::node; pad_button get_pad_button(T id) { std::lock_guard lock(m_mutex); if (cfg_pad_btn<T>* item = get_button(id)) { return item->get(); } return pad_button::pad_button_max_enum; } pad_button default_pad_button(T id) { std::lock_guard lock(m_mutex); if (cfg_pad_btn<T>* item = get_button(id)) { return item->get_default(); } return pad_button::pad_button_max_enum; } void set_button(T id, pad_button btn_id) { std::lock_guard lock(m_mutex); if (cfg_pad_btn<T>* item = get_button(id)) { item->set(btn_id); } } void init_buttons() { std::lock_guard lock(m_mutex); for (const auto& n : get_nodes()) { init_button(static_cast<cfg_pad_btn<T>*>(n)); } } void clear_buttons() { std::lock_guard lock(m_mutex); buttons.clear(); button_map.clear(); } void handle_input(std::shared_ptr<Pad> pad, bool press_only, const std::function<void(T, u16, bool)>& func) const { if (!pad) return; for (const Button& button : pad->m_buttons) { if (button.m_pressed || !press_only) { handle_input(func, button.m_offset, button.m_outKeyCode, button.m_value, button.m_pressed, true); } } for (const AnalogStick& stick : pad->m_sticks) { handle_input(func, stick.m_offset, get_axis_keycode(stick.m_offset, stick.m_value), stick.m_value, true, true); } } void handle_input(const Mouse& mouse, const std::function<void(T, u16, bool)>& func) const { for (int i = 0; i < 7; i++) { const MouseButtonCodes cell_code = get_mouse_button_code(i); if ((mouse.buttons & cell_code)) { const pad_button button = static_cast<pad_button>(static_cast<int>(pad_button::mouse_button_1) + i); const u32 offset = pad_button_offset(button); const u32 keycode = pad_button_keycode(button); handle_input(func, offset, keycode, 255, true, true); } } } protected: mutable shared_mutex m_mutex; std::vector<cfg_pad_btn<T>*> buttons; std::map<u32, std::map<u32, std::set<const cfg_pad_btn<T>*>>> button_map; cfg_pad_btn<T>* get_button(T id) { for (cfg_pad_btn<T>* item : buttons) { if (item && item->btn_id() == id) { return item; } } return nullptr; } void init_button(cfg_pad_btn<T>* pbtn) { if (!pbtn) return; const u32 offset = pad_button_offset(pbtn->get()); const u32 keycode = pad_button_keycode(pbtn->get()); button_map[offset][keycode].insert(std::as_const(pbtn)); buttons.push_back(pbtn); } const std::set<const cfg_pad_btn<T>*>& find_button(u32 offset, u32 keycode) const { if (const auto it = button_map.find(offset); it != button_map.cend()) { if (const auto it2 = it->second.find(keycode); it2 != it->second.cend() && !it2->second.empty()) { return it2->second; } } static const std::set<const cfg_pad_btn<T>*> empty_set; return empty_set; } void handle_input(const std::function<void(T, u16, bool)>& func, u32 offset, u32 keycode, u16 value, bool pressed, bool check_axis) const { m_mutex.lock(); const auto& btns = find_button(offset, keycode); if (btns.empty()) { m_mutex.unlock(); if (check_axis) { switch (offset) { case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X: case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y: case CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X: case CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y: handle_input(func, offset, static_cast<u32>(axis_direction::both), value, pressed, false); break; default: break; } } return; } for (const auto& btn : btns) { if (btn && func) { func(btn->btn_id(), value, pressed); } } m_mutex.unlock(); } }; template <typename T, u32 Count> struct emulated_pads_config : cfg::node { emulated_pads_config(std::string id) : cfg_id(std::move(id)) { for (u32 i = 0; i < Count; i++) { players.at(i) = std::make_shared<T>(this, fmt::format("Player %d", i + 1)); } } shared_mutex m_mutex; std::string cfg_id; std::array<std::shared_ptr<T>, Count> players; bool load() { m_mutex.lock(); bool result = false; const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id); cfg_log.notice("Loading %s config: %s", cfg_id, cfg_name); from_default(); for (std::shared_ptr<T>& player : players) { player->clear_buttons(); } if (fs::file cfg_file{ cfg_name, fs::read }) { if (const std::string content = cfg_file.to_string(); !content.empty()) { result = from_string(content); } for (std::shared_ptr<T>& player : players) { player->init_buttons(); } m_mutex.unlock(); } else { m_mutex.unlock(); save(); } return result; } void save() { std::lock_guard lock(m_mutex); const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id); cfg_log.notice("Saving %s config to '%s'", cfg_id, cfg_name); if (!fs::create_path(fs::get_parent_dir(cfg_name))) { cfg_log.fatal("Failed to create path: %s (%s)", cfg_name, fs::g_tls_error); } if (!cfg::node::save(cfg_name)) { cfg_log.error("Failed to save %s config to '%s' (error=%s)", cfg_id, cfg_name, fs::g_tls_error); } for (std::shared_ptr<T>& player : players) { player->clear_buttons(); player->init_buttons(); } } };
5,887
C++
.h
231
22.359307
138
0.650615
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,194
RB3MidiDrums.h
RPCS3_rpcs3/rpcs3/Emu/Io/RB3MidiDrums.h
#pragma once #include "Emu/Io/usb_device.h" #include <rtmidi_c.h> #include <chrono> #include <vector> #include <optional> namespace rb3drums { struct KitState { std::chrono::steady_clock::time_point expiry; u8 kick_pedal{}; u8 hihat_pedal{}; u8 snare{}; u8 snare_rim{}; u8 hi_tom{}; u8 low_tom{}; u8 floor_tom{}; u8 hihat{}; u8 ride{}; u8 crash{}; // Buttons triggered by combos. bool start{}; bool select{}; // Special flag that keeps kick pedal held until toggled off. // This is used in rb3 to access the category select dropdown in the song list. bool toggle_hold_kick{}; bool is_cymbal() const; bool is_drum() const; }; } // namespace rb3drums namespace midi { enum class Id : u8 { // Each 'Note' can be triggered by multiple different numbers. // Keeping them flattened in an enum for simplicity / switch statement usage. // These follow the rockband 3 midi pro adapter support. Snare0 = 38, Snare1 = 31, Snare2 = 34, Snare3 = 37, Snare4 = 39, HiTom0 = 48, HiTom1 = 50, LowTom0 = 45, LowTom1 = 47, FloorTom0 = 41, FloorTom1 = 43, Hihat0 = 22, Hihat1 = 26, Hihat2 = 42, Hihat3 = 54, Ride0 = 51, Ride1 = 53, Ride2 = 56, Ride3 = 59, Crash0 = 49, Crash1 = 52, Crash2 = 55, Crash3 = 57, Kick0 = 33, Kick1 = 35, Kick2 = 36, HihatPedal = 44, // These are from alesis nitro mesh max. ymmv. SnareRim = 40, // midi pro adapter counts this as snare. HihatWithPedalUp = 46, // The midi pro adapter considers this a normal hihat hit. HihatPedalPartial = 23, // If pedal is not 100% down, this will be sent instead of a normal hihat hit. // Internal value used for converting midi CC. // Values past 127 are not used in midi notes. MidiCC = 255, }; // Intermediate mapping regardless of which midi ids triggered it. enum class Note : u8 { Invalid, Kick, HihatPedal, Snare, SnareRim, HiTom, LowTom, FloorTom, HihatWithPedalUp, Hihat, Ride, Crash, }; } class usb_device_rb3_midi_drums : public usb_device_emulated { public: usb_device_rb3_midi_drums(const std::array<u8, 7>& location, const std::string& device_name); ~usb_device_rb3_midi_drums(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: usz response_pos{}; bool buttons_enabled{}; RtMidiInPtr midi_in{}; std::vector<rb3drums::KitState> kit_states; bool hold_kick{}; bool midi_cc_triggered{}; struct Definition { std::string name; std::vector<u8> notes; std::function<rb3drums::KitState()> create_state; Definition(std::string name, const std::string_view csv, const std::function<rb3drums::KitState()> create_state); }; class ComboTracker { public: void reload_definitions(); void add(u8 note); void reset(); std::optional<rb3drums::KitState> take_state(); private: std::chrono::steady_clock::time_point expiry; std::vector<u8> midi_notes; std::vector<Definition> m_definitions; }; ComboTracker combo; std::unordered_map<midi::Id, midi::Note> m_id_to_note_mapping; midi::Note id_to_note(midi::Id id); rb3drums::KitState parse_midi_message(u8* msg, usz size); rb3drums::KitState parse_midi_note(u8 id, u8 velocity); bool is_midi_cc(u8 id, u8 value); void write_state(u8* buf, const rb3drums::KitState&); };
3,398
C++
.h
131
23.854962
146
0.727778
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,195
topshotfearmaster_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/topshotfearmaster_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class topshotfearmaster_btn { trigger, heartrate, square, cross, circle, triangle, select, start, l3, ps, dpad_up, dpad_down, dpad_left, dpad_right, ls_x, ls_y, count }; struct cfg_tsf final : public emulated_pad_config<topshotfearmaster_btn> { cfg_tsf(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<topshotfearmaster_btn> trigger{this, "Trigger", topshotfearmaster_btn::trigger, pad_button::mouse_button_1}; cfg_pad_btn<topshotfearmaster_btn> heartrate{this, "Heartrate", topshotfearmaster_btn::heartrate, pad_button::mouse_button_2}; cfg_pad_btn<topshotfearmaster_btn> square{this, "Square", topshotfearmaster_btn::square, pad_button::square}; cfg_pad_btn<topshotfearmaster_btn> cross{this, "Cross", topshotfearmaster_btn::cross, pad_button::cross}; cfg_pad_btn<topshotfearmaster_btn> circle{this, "Circle", topshotfearmaster_btn::circle, pad_button::circle}; cfg_pad_btn<topshotfearmaster_btn> triangle{this, "Triangle", topshotfearmaster_btn::triangle, pad_button::triangle}; cfg_pad_btn<topshotfearmaster_btn> select{this, "Select", topshotfearmaster_btn::select, pad_button::select}; cfg_pad_btn<topshotfearmaster_btn> start{this, "Start", topshotfearmaster_btn::start, pad_button::start}; cfg_pad_btn<topshotfearmaster_btn> l3{this, "L3", topshotfearmaster_btn::l3, pad_button::L3}; cfg_pad_btn<topshotfearmaster_btn> ps{this, "PS", topshotfearmaster_btn::ps, pad_button::ps}; cfg_pad_btn<topshotfearmaster_btn> dpad_up{this, "D-Pad Up", topshotfearmaster_btn::dpad_up, pad_button::dpad_up}; cfg_pad_btn<topshotfearmaster_btn> dpad_down{this, "D-Pad Down", topshotfearmaster_btn::dpad_down, pad_button::dpad_down}; cfg_pad_btn<topshotfearmaster_btn> dpad_left{this, "D-Pad Left", topshotfearmaster_btn::dpad_left, pad_button::dpad_left}; cfg_pad_btn<topshotfearmaster_btn> dpad_right{this, "D-Pad Right", topshotfearmaster_btn::dpad_right, pad_button::dpad_right}; cfg_pad_btn<topshotfearmaster_btn> ls_x{this, "Left Stick X-Axis", topshotfearmaster_btn::ls_x, pad_button::ls_x}; cfg_pad_btn<topshotfearmaster_btn> ls_y{this, "Left Stick Y-Axis", topshotfearmaster_btn::ls_y, pad_button::ls_y}; }; struct cfg_topshotfearmaster final : public emulated_pads_config<cfg_tsf, 4> { cfg_topshotfearmaster() : emulated_pads_config<cfg_tsf, 4>("topshotfearmaster") {}; }; extern cfg_topshotfearmaster g_cfg_topshotfearmaster;
2,477
C++
.h
48
49.708333
127
0.767451
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,196
MouseHandler.h
RPCS3_rpcs3/rpcs3/Emu/Io/MouseHandler.h
#pragma once #include <list> #include <vector> #include "Utilities/StrFmt.h" #include "Utilities/mutex.h" #include "util/init_mutex.hpp" #include "Emu/system_config_types.h" // TODO: HLE info (constants, structs, etc.) should not be available here enum { // is_supported CELL_MOUSE_INFO_TABLET_NOT_SUPPORTED = 0, CELL_MOUSE_INFO_TABLET_SUPPORTED = 1, // mode CELL_MOUSE_INFO_TABLET_MOUSE_MODE = 1, CELL_MOUSE_INFO_TABLET_TABLET_MODE = 2, }; enum MousePortStatus { CELL_MOUSE_STATUS_DISCONNECTED = 0x00000000, CELL_MOUSE_STATUS_CONNECTED = 0x00000001, }; enum MouseDataUpdate { CELL_MOUSE_DATA_UPDATE = 1, CELL_MOUSE_DATA_NON = 0, }; enum MouseButtonCodes { CELL_MOUSE_BUTTON_1 = 0x00000001, CELL_MOUSE_BUTTON_2 = 0x00000002, CELL_MOUSE_BUTTON_3 = 0x00000004, CELL_MOUSE_BUTTON_4 = 0x00000008, CELL_MOUSE_BUTTON_5 = 0x00000010, CELL_MOUSE_BUTTON_6 = 0x00000020, CELL_MOUSE_BUTTON_7 = 0x00000040, CELL_MOUSE_BUTTON_8 = 0x00000080, }; enum { CELL_MOUSE_INFO_INTERCEPTED = 1 }; static inline MouseButtonCodes get_mouse_button_code(int i) { switch (i) { case 0: return CELL_MOUSE_BUTTON_1; case 1: return CELL_MOUSE_BUTTON_2; case 2: return CELL_MOUSE_BUTTON_3; case 3: return CELL_MOUSE_BUTTON_4; case 4: return CELL_MOUSE_BUTTON_5; case 5: return CELL_MOUSE_BUTTON_6; case 6: return CELL_MOUSE_BUTTON_7; case 7: return CELL_MOUSE_BUTTON_8; default: fmt::throw_exception("get_mouse_button_code: Invalid index %d", i); } } static const u32 MAX_MICE = 127; static const u32 MOUSE_MAX_DATA_LIST_NUM = 8; static const u32 MOUSE_MAX_CODES = 64; struct MouseInfo { u32 max_connect = 0; u32 now_connect = 0; u32 info = 0; u32 mode[MAX_MICE]{}; // TODO: tablet support u32 tablet_is_supported[MAX_MICE]{}; // TODO: tablet support u16 vendor_id[MAX_MICE]{}; u16 product_id[MAX_MICE]{}; u8 status[MAX_MICE]{}; bool is_null_handler = false; }; struct MouseRawData { s32 len = 0; u8 data[MOUSE_MAX_CODES]{}; }; struct MouseData { u8 update = 0; u8 buttons = 0; s8 x_axis = 0; s8 y_axis = 0; s8 wheel = 0; s8 tilt = 0; }; struct MouseTabletData { s32 len = 0; u8 data[MOUSE_MAX_CODES]{}; }; using MouseTabletDataList = std::list<MouseTabletData>; using MouseDataList = std::list<MouseData>; struct Mouse { s32 x_pos = 0; s32 y_pos = 0; s32 x_max = 0; s32 y_max = 0; u8 buttons = 0; // actual mouse button positions MouseTabletDataList m_tablet_datalist{}; MouseDataList m_datalist{}; MouseRawData m_rawdata{}; }; class MouseHandlerBase { protected: MouseInfo m_info{}; std::vector<Mouse> m_mice; steady_clock::time_point last_update{}; bool is_time_for_update(double elapsed_time = 10.0); // 4-10 ms, let's use 10 for now public: shared_mutex mutex; virtual void Init(const u32 max_connect) = 0; virtual ~MouseHandlerBase() = default; SAVESTATE_INIT_POS(18); MouseHandlerBase(){}; MouseHandlerBase(const MouseHandlerBase&) = delete; MouseHandlerBase(utils::serial* ar); MouseHandlerBase(utils::serial& ar) : MouseHandlerBase(&ar) {} void save(utils::serial& ar); void Button(u32 index, u8 button, bool pressed); void Scroll(u32 index, s8 x, s8 y); void Move(u32 index, s32 x_pos_new, s32 y_pos_new, s32 x_max, s32 y_max, bool is_relative = false, s32 x_delta = 0, s32 y_delta = 0); void SetIntercepted(bool intercepted); MouseInfo& GetInfo() { return m_info; } std::vector<Mouse>& GetMice() { return m_mice; } MouseDataList& GetDataList(const u32 mouse) { return m_mice[mouse].m_datalist; } MouseTabletDataList& GetTabletDataList(const u32 mouse) { return m_mice[mouse].m_tablet_datalist; } MouseRawData& GetRawData(const u32 mouse) { return m_mice[mouse].m_rawdata; } stx::init_mutex init; mouse_handler type = mouse_handler::null; };
3,744
C++
.h
133
26.323308
134
0.735696
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,197
usb_device.h
RPCS3_rpcs3/rpcs3/Emu/Io/usb_device.h
#pragma once #ifdef _MSC_VER #pragma warning(push, 0) #else #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wall" #pragma GCC diagnostic ignored "-Wextra" #pragma GCC diagnostic ignored "-Wold-style-cast" #endif #include <libusb.h> #ifdef _MSC_VER #pragma warning(pop) #else #pragma GCC diagnostic pop #endif #include "Emu/Cell/lv2/sys_usbd.h" struct UsbTransfer; // Usb descriptors enum : u8 { USB_DESCRIPTOR_DEVICE = 0x01, USB_DESCRIPTOR_CONFIG = 0x02, USB_DESCRIPTOR_STRING = 0x03, USB_DESCRIPTOR_INTERFACE = 0x04, USB_DESCRIPTOR_ENDPOINT = 0x05, USB_DESCRIPTOR_HID = 0x21, USB_DESCRIPTOR_ACI = 0x24, USB_DESCRIPTOR_ENDPOINT_ASI = 0x25, }; struct UsbDeviceDescriptor { le_t<u16, 1> bcdUSB; u8 bDeviceClass; u8 bDeviceSubClass; u8 bDeviceProtocol; u8 bMaxPacketSize0; le_t<u16, 1> idVendor; le_t<u16, 1> idProduct; le_t<u16, 1> bcdDevice; u8 iManufacturer; u8 iProduct; u8 iSerialNumber; u8 bNumConfigurations; }; struct UsbDeviceConfiguration { le_t<u16, 1> wTotalLength; u8 bNumInterfaces; u8 bConfigurationValue; u8 iConfiguration; u8 bmAttributes; u8 bMaxPower; }; struct UsbDeviceInterface { u8 bInterfaceNumber; u8 bAlternateSetting; u8 bNumEndpoints; u8 bInterfaceClass; u8 bInterfaceSubClass; u8 bInterfaceProtocol; u8 iInterface; }; struct UsbDeviceEndpoint { u8 bEndpointAddress; u8 bmAttributes; le_t<u16, 1> wMaxPacketSize; u8 bInterval; }; struct UsbDeviceHID { le_t<u16, 1> bcdHID; u8 bCountryCode; u8 bNumDescriptors; u8 bDescriptorType; le_t<u16, 1> wDescriptorLength; }; struct UsbTransfer { u32 assigned_number = 0; u32 transfer_id = 0; s32 result = 0; u32 count = 0; UsbDeviceIsoRequest iso_request{}; std::vector<u8> setup_buf; libusb_transfer* transfer = nullptr; bool busy = false; // For control transfers u8 *control_destbuf = nullptr; // For fake transfers bool fake = false; u64 expected_time = 0; s32 expected_result = 0; u32 expected_count = 0; }; // Usb descriptor helper struct UsbDescriptorNode { u8 bLength{}; u8 bDescriptorType{}; union { UsbDeviceDescriptor _device; UsbDeviceConfiguration _configuration; UsbDeviceInterface _interface; UsbDeviceEndpoint _endpoint; UsbDeviceHID _hid; u8 data[0xFF]{}; }; std::vector<UsbDescriptorNode> subnodes; UsbDescriptorNode() {} template <typename T> UsbDescriptorNode(u8 _bDescriptorType, const T& _data) : bLength(sizeof(T) + 2), bDescriptorType(_bDescriptorType) { memcpy(data, &_data, sizeof(T)); } UsbDescriptorNode(u8 _bLength, u8 _bDescriptorType, u8* _data) : bLength(_bLength), bDescriptorType(_bDescriptorType) { memcpy(data, _data, _bLength - 2); } UsbDescriptorNode& add_node(const UsbDescriptorNode& newnode) { subnodes.push_back(newnode); return subnodes.back(); } u32 get_size() const { u32 nodesize = bLength; for (const auto& node : subnodes) { nodesize += node.get_size(); } return nodesize; } u32 write_data(u8* ptr, u32 max_size) const { u32 size = std::min<u32>(bLength, max_size); memcpy(ptr, this, size); for (const auto& node : subnodes) { const u32 remaining = max_size - size; if (remaining == 0) break; size += node.write_data(ptr + size, remaining); } return size; } }; class usb_device { public: usb_device(const std::array<u8, 7>& location); virtual ~usb_device() = default; virtual bool open_device() = 0; void get_location(u8* location) const; virtual void read_descriptors(); virtual u32 get_configuration(u8* buf); virtual bool set_configuration(u8 cfg_num); virtual bool set_interface(u8 int_num); virtual void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) = 0; virtual void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) = 0; virtual void isochronous_transfer(UsbTransfer* transfer) = 0; public: // device ID if the device has been ldded(0 otherwise) u32 assigned_number = 0; // base device descriptor, every other descriptor is a subnode UsbDescriptorNode device; protected: u8 current_config = 1; u8 current_interface = 0; std::array<u8, 7> location{}; protected: static u64 get_timestamp(); }; class usb_device_passthrough : public usb_device { public: usb_device_passthrough(libusb_device* _device, libusb_device_descriptor& desc, const std::array<u8, 7>& location); ~usb_device_passthrough(); bool open_device() override; void read_descriptors() override; u32 get_configuration(u8* buf) override; bool set_configuration(u8 cfg_num) override; bool set_interface(u8 int_num) override; void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; void isochronous_transfer(UsbTransfer* transfer) override; protected: void send_libusb_transfer(libusb_transfer* transfer); protected: libusb_device* lusb_device = nullptr; libusb_device_handle* lusb_handle = nullptr; }; class usb_device_emulated : public usb_device { public: usb_device_emulated(const std::array<u8, 7>& location); usb_device_emulated(const UsbDeviceDescriptor& _device, const std::array<u8, 7>& location); bool open_device() override; void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; void isochronous_transfer(UsbTransfer* transfer) override; // Emulated specific functions void add_string(std::string str); u32 get_descriptor(u8 type, u8 index, u8* buf, u32 buf_size); u32 get_status(bool self_powered, bool remote_wakeup, u8* buf, u32 buf_size); protected: std::vector<std::string> strings; };
6,116
C++
.h
211
26.952607
149
0.734492
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,198
mouse_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/mouse_config.h
#pragma once #include "Utilities/Config.h" // For simplicity's sake, there is only one config instead of 127 for MAX_MICE struct mouse_config final : cfg::node { mouse_config(); const std::string cfg_name; cfg::string mouse_button_1{ this, "Button 1", "Mouse Left", true }; cfg::string mouse_button_2{ this, "Button 2", "Mouse Right", true }; cfg::string mouse_button_3{ this, "Button 3", "Mouse Middle", true }; cfg::string mouse_button_4{ this, "Button 4", "", true }; cfg::string mouse_button_5{ this, "Button 5", "", true }; cfg::string mouse_button_6{ this, "Button 6", "", true }; cfg::string mouse_button_7{ this, "Button 7", "", true }; cfg::string mouse_button_8{ this, "Button 8", "", true }; atomic_t<bool> reload_requested = true; bool exist() const; bool load(); void save(); cfg::string& get_button(int code); }; extern mouse_config g_cfg_mouse;
883
C++
.h
22
38.090909
78
0.68347
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,199
usio_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/usio_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class usio_btn { test, coin, service, enter, up, down, left, right, taiko_hit_side_left, taiko_hit_side_right, taiko_hit_center_left, taiko_hit_center_right, tekken_button1, tekken_button2, tekken_button3, tekken_button4, tekken_button5, count }; struct cfg_usio final : public emulated_pad_config<usio_btn> { cfg_usio(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<usio_btn> test{ this, "Test", usio_btn::test, pad_button::select }; cfg_pad_btn<usio_btn> coin{ this, "Coin", usio_btn::coin, pad_button::L3 }; cfg_pad_btn<usio_btn> service{this, "Service", usio_btn::service, pad_button::R3}; cfg_pad_btn<usio_btn> enter{ this, "Enter/Start", usio_btn::enter, pad_button::start }; cfg_pad_btn<usio_btn> up{ this, "Up", usio_btn::up, pad_button::dpad_up }; cfg_pad_btn<usio_btn> down{ this, "Down", usio_btn::down, pad_button::dpad_down }; cfg_pad_btn<usio_btn> left{this, "Left", usio_btn::left, pad_button::dpad_left}; cfg_pad_btn<usio_btn> right{this, "Right", usio_btn::right, pad_button::dpad_right}; cfg_pad_btn<usio_btn> taiko_hit_side_left{ this, "Taiko Hit Side Left", usio_btn::taiko_hit_side_left, pad_button::square }; cfg_pad_btn<usio_btn> taiko_hit_side_right{ this, "Taiko Hit Side Right", usio_btn::taiko_hit_side_right, pad_button::circle }; cfg_pad_btn<usio_btn> taiko_hit_center_left{ this, "Taiko Hit Center Left", usio_btn::taiko_hit_center_left, pad_button::triangle }; cfg_pad_btn<usio_btn> taiko_hit_center_right{ this, "Taiko Hit Center Right", usio_btn::taiko_hit_center_right, pad_button::cross }; cfg_pad_btn<usio_btn> tekken_button1{this, "Tekken Button 1", usio_btn::tekken_button1, pad_button::square}; cfg_pad_btn<usio_btn> tekken_button2{this, "Tekken Button 2", usio_btn::tekken_button2, pad_button::triangle}; cfg_pad_btn<usio_btn> tekken_button3{this, "Tekken Button 3", usio_btn::tekken_button3, pad_button::cross}; cfg_pad_btn<usio_btn> tekken_button4{this, "Tekken Button 4", usio_btn::tekken_button4, pad_button::circle}; cfg_pad_btn<usio_btn> tekken_button5{this, "Tekken Button 5", usio_btn::tekken_button5, pad_button::R1}; }; struct cfg_usios final : public emulated_pads_config<cfg_usio, 4> { cfg_usios() : emulated_pads_config<cfg_usio, 4>("usio") {}; }; extern cfg_usios g_cfg_usio;
2,383
C++
.h
50
45.76
133
0.723441
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,200
rb3drums_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/rb3drums_config.h
#pragma once #include "Utilities/Config.h" struct cfg_rb3drums final : cfg::node { cfg_rb3drums(); bool load(); void save(); cfg::uint<1, 100> pulse_ms{this, "Pulse width ms", 30, true}; cfg::uint<1, 127> minimum_velocity{this, "Minimum velocity", 10, true}; cfg::uint<1, 5000> combo_window_ms{this, "Combo window in milliseconds", 2000, true}; cfg::_bool stagger_cymbals{this, "Stagger cymbal hits", true, true}; cfg::string midi_overrides{this, "Midi id to note override", "", true}; cfg::string combo_start{this, "Combo Start", "HihatPedal,HihatPedal,HihatPedal,Snare", true}; cfg::string combo_select{this, "Combo Select", "HihatPedal,HihatPedal,HihatPedal,SnareRim", true}; cfg::string combo_toggle_hold_kick{this, "Combo Toggle Hold Kick", "HihatPedal,HihatPedal,HihatPedal,Kick", true}; cfg::uint<0, 255> midi_cc_status{this, "Midi CC status", 0xB0, true}; cfg::uint<0, 127> midi_cc_number{this, "Midi CC control number", 4, true}; cfg::uint<0, 127> midi_cc_threshold{this, "Midi CC threshold", 64, true}; cfg::_bool midi_cc_invert_threshold{this, "Midi CC invert threshold", false, true}; const std::string path; atomic_t<bool> reload_requested = false; }; extern cfg_rb3drums g_cfg_rb3drums;
1,224
C++
.h
23
51.217391
115
0.727197
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,201
KeyboardHandler.h
RPCS3_rpcs3/rpcs3/Emu/Io/KeyboardHandler.h
#pragma once #include "Keyboard.h" #include <mutex> #include <vector> #include <set> #include <unordered_map> #include "util/init_mutex.hpp" enum QtKeys { Key_Shift = 0x01000020, Key_Control = 0x01000021, Key_Meta = 0x01000022, Key_Alt = 0x01000023, Key_CapsLock = 0x01000024, Key_NumLock = 0x01000025, Key_ScrollLock = 0x01000026, Key_Super_L = 0x01000053, Key_Super_R = 0x01000054 }; // See https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values enum native_key : u32 { #ifdef _WIN32 ctrl_l = 0x001D, ctrl_r = 0xE01D, shift_l = 0x002A, shift_r = 0x0036, alt_l = 0x0038, alt_r = 0xE038, meta_l = 0xE05B, meta_r = 0xE05C, #elif defined (__APPLE__) ctrl_l = 0x3B, // kVK_Control ctrl_r = 0x3E, // kVK_RightControl shift_l = 0x38, // kVK_Shift shift_r = 0x3C, // kVK_RightShift alt_l = 0x3A, // kVK_Option alt_r = 0x3D, // kVK_RightOption meta_l = 0x37, // kVK_Command meta_r = 0x36, // kVK_RightCommand #else ctrl_l = 0x0025, ctrl_r = 0x0069, shift_l = 0x0032, shift_r = 0x003E, alt_l = 0x0040, alt_r = 0x006C, meta_l = 0x0085, meta_r = 0x0086, #endif }; struct KbInfo { u32 max_connect = 0; u32 now_connect = 0; u32 info = 0; bool is_null_handler = false; std::array<u8, CELL_KB_MAX_KEYBOARDS> status{}; }; struct KbButton { u32 m_keyCode = 0; u32 m_outKeyCode = 0; bool m_pressed = false; KbButton() = default; KbButton(u32 keyCode, u32 outKeyCode, bool pressed = false) : m_keyCode(keyCode) , m_outKeyCode(outKeyCode) , m_pressed(pressed) { } }; struct KbData { u32 led = 0; // Active led lights TODO: Set initial state of led u32 mkey = 0; // Active key modifiers s32 len = 0; // Number of key codes (0 means no data available) std::array<KbButton, CELL_KB_MAX_KEYCODES> buttons{}; }; struct KbExtraData { std::set<std::u32string> pressed_keys{}; }; struct KbConfig { u32 arrange = CELL_KB_MAPPING_101; u32 read_mode = CELL_KB_RMODE_INPUTCHAR; u32 code_type = CELL_KB_CODETYPE_ASCII; }; struct Keyboard { bool m_key_repeat = false; KbData m_data{}; KbExtraData m_extra_data{}; KbConfig m_config{}; std::unordered_map<u32, KbButton> m_keys; }; class keyboard_consumer { public: enum class identifier { unknown, overlays, cellKb, }; keyboard_consumer() {} keyboard_consumer(identifier id) : m_id(id) {} bool ConsumeKey(u32 qt_code, u32 native_code, bool pressed, bool is_auto_repeat, const std::u32string& key); void SetIntercepted(bool intercepted); static bool IsMetaKey(u32 code); KbInfo& GetInfo() { return m_info; } std::vector<Keyboard>& GetKeyboards() { return m_keyboards; } KbData& GetData(const u32 keyboard) { return m_keyboards[keyboard].m_data; } KbExtraData& GetExtraData(const u32 keyboard) { return m_keyboards[keyboard].m_extra_data; } KbConfig& GetConfig(const u32 keyboard) { return m_keyboards[keyboard].m_config; } identifier id() const { return m_id; } void ReleaseAllKeys(); protected: u32 get_out_key_code(u32 qt_code, u32 native_code, u32 out_key_code); identifier m_id = identifier::unknown; KbInfo m_info{}; std::vector<Keyboard> m_keyboards; }; class KeyboardHandlerBase { public: std::mutex m_mutex; virtual void Init(keyboard_consumer& consumer, const u32 max_connect) = 0; virtual ~KeyboardHandlerBase() = default; KeyboardHandlerBase(utils::serial* ar); KeyboardHandlerBase(utils::serial& ar) : KeyboardHandlerBase(&ar) {} void save(utils::serial& ar); SAVESTATE_INIT_POS(19); keyboard_consumer& AddConsumer(keyboard_consumer::identifier id, u32 max_connect); keyboard_consumer& GetConsumer(keyboard_consumer::identifier id); void RemoveConsumer(keyboard_consumer::identifier id); bool HandleKey(u32 qt_code, u32 native_code, bool pressed, bool is_auto_repeat, const std::u32string& key); void SetIntercepted(bool intercepted); stx::init_mutex init; protected: void ReleaseAllKeys(); bool m_keys_released = false; std::unordered_map<keyboard_consumer::identifier, keyboard_consumer> m_consumers; };
4,043
C++
.h
145
25.958621
109
0.729129
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,202
RB3MidiKeyboard.h
RPCS3_rpcs3/rpcs3/Emu/Io/RB3MidiKeyboard.h
#pragma once #include "Emu/Io/usb_device.h" #include <rtmidi_c.h> class usb_device_rb3_midi_keyboard : public usb_device_emulated { private: usz response_pos = 0; bool buttons_enabled = false; RtMidiInPtr midi_in{}; // button states // TODO: emulate velocity struct { u8 count = 0; bool cross = false; bool circle = false; bool square = false; bool triangle = false; bool start = false; bool select = false; bool overdrive = false; bool dpad_up = false; bool dpad_down = false; bool dpad_left = false; bool dpad_right = false; std::array<bool, 25> keys{}; std::array<u8, 25> velocities{}; s16 pitch_wheel = 0; } button_state; void parse_midi_message(u8* msg, usz size); void write_state(u8* buf); public: usb_device_rb3_midi_keyboard(const std::array<u8, 7>& location, const std::string& device_name); ~usb_device_rb3_midi_keyboard(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; };
1,134
C++
.h
37
28.135135
146
0.725346
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,203
PadHandler.h
RPCS3_rpcs3/rpcs3/Emu/Io/PadHandler.h
#pragma once #include "pad_types.h" #include "pad_config.h" #include "pad_config_types.h" #include "util/types.hpp" #include <cmath> #include <functional> #include <string> #include <set> #include <vector> #include <memory> #include <unordered_map> LOG_CHANNEL(input_log, "Input"); class PadDevice { public: virtual ~PadDevice() = default; cfg_pad* config{ nullptr }; u8 player_id{0}; u8 large_motor{0}; u8 small_motor{0}; bool new_output_data{true}; steady_clock::time_point last_output; std::set<u64> trigger_code_left{}; std::set<u64> trigger_code_right{}; std::array<std::set<u64>, 4> axis_code_left{}; std::array<std::set<u64>, 4> axis_code_right{}; }; struct pad_ensemble { std::shared_ptr<Pad> pad; std::shared_ptr<PadDevice> device; std::shared_ptr<PadDevice> buddy_device; explicit pad_ensemble(std::shared_ptr<Pad> _pad, std::shared_ptr<PadDevice> _device, std::shared_ptr<PadDevice> _buddy_device) : pad(_pad), device(_device), buddy_device(_buddy_device) {} }; struct pad_list_entry { std::string name; bool is_buddy_only = false; explicit pad_list_entry(std::string _name, bool _is_buddy_only) : name(std::move(_name)), is_buddy_only(_is_buddy_only) {} }; using pad_preview_values = std::array<int, 6>; using pad_callback = std::function<void(u16 /*button_value*/, std::string /*button_name*/, std::string /*pad_name*/, u32 /*battery_level*/, pad_preview_values /*preview_values*/)>; using pad_fail_callback = std::function<void(std::string /*pad_name*/)>; using motion_preview_values = std::array<u16, 4>; using motion_callback = std::function<void(std::string /*pad_name*/, motion_preview_values /*preview_values*/)>; using motion_fail_callback = std::function<void(std::string /*pad_name*/, motion_preview_values /*preview_values*/)>; class PadHandlerBase { public: enum class connection { no_data, connected, disconnected }; enum class trigger_recognition_mode { any, // Add all trigger modes to the button map one_directional, // Treat trigger axis as one-directional only two_directional // Treat trigger axis as two-directional only (similar to sticks) }; protected: enum button { up, down, left, right, cross, square, circle, triangle, l1, l2, l3, r1, r2, r3, start, select, ps, //reserved, ls_left, ls_right, ls_down, ls_up, rs_left, rs_right, rs_down, rs_up, skateboard_ir_nose, skateboard_ir_tail, skateboard_ir_left, skateboard_ir_right, skateboard_tilt_left, skateboard_tilt_right, pressure_intensity_button, analog_limiter_button, button_count }; static constexpr u32 MAX_GAMEPADS = 7; static constexpr u16 button_press_threshold = 50; static constexpr u16 touch_threshold = static_cast<u16>(255 * 0.9f); static constexpr auto min_output_interval = 300ms; std::array<bool, MAX_GAMEPADS> last_connection_status{{ false, false, false, false, false, false, false }}; std::string m_name_string; usz m_max_devices = 0; u32 m_trigger_threshold = 0; u32 m_thumb_threshold = 0; trigger_recognition_mode m_trigger_recognition_mode = trigger_recognition_mode::any; bool b_has_led = false; bool b_has_rgb = false; bool b_has_player_led = false; bool b_has_battery = false; bool b_has_battery_led = false; bool b_has_deadzones = false; bool b_has_rumble = false; bool b_has_motion = false; bool b_has_config = false; bool b_has_pressure_intensity_button = true; bool b_has_analog_limiter_button = true; std::array<cfg_pad, MAX_GAMEPADS> m_pad_configs; std::vector<pad_ensemble> m_bindings; std::unordered_map<u32, std::string> button_list; std::unordered_map<u32, u16> min_button_values; std::set<u32> blacklist; static std::set<u32> narrow_set(const std::set<u64>& src); // Search an unordered map for a string value and return found keycode template <typename S, typename T> static std::set<T> FindKeyCodes(const std::unordered_map<S, std::string>& map, const cfg::string& cfg_string, bool fallback = true) { std::set<T> key_codes; const std::string& def = cfg_string.def; const std::vector<std::string> names = cfg_pad::get_buttons(cfg_string); T def_code = umax; for (const std::string& nam : names) { for (const auto& [code, name] : map) { if (name == nam) { key_codes.insert(static_cast<T>(code)); } if (fallback && name == def) def_code = static_cast<T>(code); } } if (!key_codes.empty()) { return key_codes; } if (fallback) { if (!names.empty()) input_log.error("FindKeyCode for [name = %s] returned with [def_code = %d] for [def = %s]", cfg_string.to_string(), def_code, def); if (def_code != umax) { return { def_code }; } } return {}; } // Search an unordered map for a string value and return found keycode template <typename S, typename T> static std::set<T> FindKeyCodes(const std::unordered_map<S, std::string>& map, const std::vector<std::string>& names) { std::set<T> key_codes; for (const std::string& name : names) { for (const auto& [code, nam] : map) { if (nam == name) { key_codes.insert(static_cast<T>(code)); break; } } } if (!key_codes.empty()) { return key_codes; } return {}; } // Get new multiplied value based on the multiplier static s32 MultipliedInput(s32 raw_value, s32 multiplier); // Get new scaled value between 0 and 255 based on its minimum and maximum static f32 ScaledInput(f32 raw_value, f32 minimum, f32 maximum, f32 deadzone, f32 range = 255.0f); // Get new scaled value between -255 and 255 based on its minimum and maximum static f32 ScaledAxisInput(f32 raw_value, f32 minimum, f32 maximum, f32 deadzone, f32 range = 255.0f); // Get normalized trigger value based on the range defined by a threshold u16 NormalizeTriggerInput(u16 value, u32 threshold) const; // normalizes a directed input, meaning it will correspond to a single "button" and not an axis with two directions // the input values must lie in 0+ u16 NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum) const; // This function normalizes stick deadzone based on the DS3's deadzone, which is ~13% // X and Y is expected to be in (-255) to 255 range, deadzone should be in terms of thumb stick range // return is new x and y values in 0-255 range std::tuple<u16, u16> NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone, u32 anti_deadzone) const; // get clamped value between 0 and 255 static u16 Clamp0To255(f32 input); // get clamped value between 0 and 1023 static u16 Clamp0To1023(f32 input); // input has to be [-1,1]. result will be [0,255] static u16 ConvertAxis(f32 value); // The DS3, (and i think xbox controllers) give a 'square-ish' type response, so that the corners will give (almost)max x/y instead of the ~30x30 from a perfect circle // using a simple scale/sensitivity increase would *work* although it eats a chunk of our usable range in exchange // this might be the best for now, in practice it seems to push the corners to max of 20x20, with a squircle_factor of 8000 // This function assumes inX and inY is already in 0-255 static void ConvertToSquirclePoint(u16& inX, u16& inY, u32 squircle_factor); public: // u32 thumb_min = 0; // Unused. Make sure all handlers report 0+ values for sticks in get_button_values. u32 thumb_max = 255; u32 trigger_min = 0; u32 trigger_max = 255; u32 connected_devices = 0; pad_handler m_type; bool m_is_init = false; enum class gui_call_type { normal, get_connection, reset_input, blacklist }; std::vector<pad_ensemble>& bindings() { return m_bindings; } std::string name_string() const { return m_name_string; } usz max_devices() const { return m_max_devices; } bool has_config() const { return b_has_config; } bool has_rumble() const { return b_has_rumble; } bool has_motion() const { return b_has_motion; } bool has_deadzones() const { return b_has_deadzones; } bool has_led() const { return b_has_led; } bool has_rgb() const { return b_has_rgb; } bool has_player_led() const { return b_has_player_led; } bool has_battery() const { return b_has_battery; } bool has_battery_led() const { return b_has_battery_led; } bool has_pressure_intensity_button() const { return b_has_pressure_intensity_button; } bool has_analog_limiter_button() const { return b_has_analog_limiter_button; } u16 NormalizeStickInput(u16 raw_value, s32 threshold, s32 multiplier, bool ignore_threshold = false) const; void convert_stick_values(u16& x_out, u16& y_out, s32 x_in, s32 y_in, u32 deadzone, u32 anti_deadzone, u32 padsquircling) const; void set_trigger_recognition_mode(trigger_recognition_mode mode) { m_trigger_recognition_mode = mode; } virtual bool Init() { return true; } PadHandlerBase(pad_handler type = pad_handler::null); virtual ~PadHandlerBase() = default; // Sets window to config the controller(optional) virtual void SetPadData(const std::string& /*padId*/, u8 /*player_id*/, u8 /*large_motor*/, u8 /*small_motor*/, s32 /*r*/, s32 /*g*/, s32 /*b*/, bool /*player_led*/, bool /*battery_led*/, u32 /*battery_led_brightness*/) {} virtual u32 get_battery_level(const std::string& /*padId*/) { return 0; } // Return list of devices for that handler virtual std::vector<pad_list_entry> list_devices() = 0; // Callback called during pad_thread::ThreadFunc virtual void process(); // Binds a Pad to a device virtual bool bindPadToDevice(std::shared_ptr<Pad> pad); virtual void init_config(cfg_pad* cfg) = 0; virtual connection get_next_button_press(const std::string& padId, const pad_callback& callback, const pad_fail_callback& fail_callback, gui_call_type call_type, const std::vector<std::string>& buttons); virtual void get_motion_sensors(const std::string& pad_id, const motion_callback& callback, const motion_fail_callback& fail_callback, motion_preview_values preview_values, const std::array<AnalogSensor, 4>& sensors); virtual std::unordered_map<u32, std::string> get_motion_axis_list() const { return {}; } private: virtual std::shared_ptr<PadDevice> get_device(const std::string& /*device*/) { return nullptr; } virtual bool get_is_left_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; } virtual bool get_is_right_trigger(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; } virtual bool get_is_left_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; } virtual bool get_is_right_stick(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; } virtual bool get_is_touch_pad_motion(const std::shared_ptr<PadDevice>& /*device*/, u64 /*keyCode*/) { return false; } virtual PadHandlerBase::connection update_connection(const std::shared_ptr<PadDevice>& /*device*/) { return connection::disconnected; } virtual void get_extended_info(const pad_ensemble& /*binding*/) {} virtual void apply_pad_data(const pad_ensemble& /*binding*/) {} virtual std::unordered_map<u64, u16> get_button_values(const std::shared_ptr<PadDevice>& /*device*/) { return {}; } virtual pad_preview_values get_preview_values(const std::unordered_map<u64, u16>& /*data*/) { return {}; } protected: virtual std::array<std::set<u32>, PadHandlerBase::button::button_count> get_mapped_key_codes(const std::shared_ptr<PadDevice>& device, const cfg_pad* cfg); virtual void get_mapping(const pad_ensemble& binding); void TranslateButtonPress(const std::shared_ptr<PadDevice>& device, u64 keyCode, bool& pressed, u16& val, bool use_stick_multipliers, bool ignore_stick_threshold = false, bool ignore_trigger_threshold = false); void init_configs(); cfg_pad* get_config(const std::string& pad_id); };
11,722
C++
.h
282
39.031915
223
0.72111
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,204
Keyboard.h
RPCS3_rpcs3/rpcs3/Emu/Io/Keyboard.h
#pragma once #include "util/types.hpp" enum { CELL_KB_INFO_INTERCEPTED = 1 }; enum { CELL_KB_MAX_KEYCODES = 62, CELL_KB_MAX_KEYBOARDS = 127, }; enum KbPortStatus { CELL_KB_STATUS_DISCONNECTED = 0x00000000, CELL_KB_STATUS_CONNECTED = 0x00000001, }; enum CellKbReadMode { CELL_KB_RMODE_INPUTCHAR = 0, CELL_KB_RMODE_PACKET = 1, }; enum CellKbCodeType { CELL_KB_CODETYPE_RAW = 0, CELL_KB_CODETYPE_ASCII = 1, }; enum KbLedCodes { CELL_KB_LED_NUM_LOCK = 0x00000001, CELL_KB_LED_CAPS_LOCK = 0x00000002, CELL_KB_LED_SCROLL_LOCK = 0x00000004, CELL_KB_LED_COMPOSE = 0x00000008, CELL_KB_LED_KANA = 0x00000016, }; enum KbMetaKeys { CELL_KB_MKEY_L_CTRL = 0x00000001, CELL_KB_MKEY_L_SHIFT = 0x00000002, CELL_KB_MKEY_L_ALT = 0x00000004, CELL_KB_MKEY_L_WIN = 0x00000008, CELL_KB_MKEY_R_CTRL = 0x00000010, CELL_KB_MKEY_R_SHIFT = 0x00000020, CELL_KB_MKEY_R_ALT = 0x00000040, CELL_KB_MKEY_R_WIN = 0x00000080, }; enum Keys { // Non-ASCII Raw data CELL_KEYC_NO_EVENT = 0x00, CELL_KEYC_E_ROLLOVER = 0x01, CELL_KEYC_E_POSTFAIL = 0x02, CELL_KEYC_E_UNDEF = 0x03, CELL_KEYC_ESCAPE = 0x29, CELL_KEYC_106_KANJI = 0x35, CELL_KEYC_CAPS_LOCK = 0x39, CELL_KEYC_F1 = 0x3a, CELL_KEYC_F2 = 0x3b, CELL_KEYC_F3 = 0x3c, CELL_KEYC_F4 = 0x3d, CELL_KEYC_F5 = 0x3e, CELL_KEYC_F6 = 0x3f, CELL_KEYC_F7 = 0x40, CELL_KEYC_F8 = 0x41, CELL_KEYC_F9 = 0x42, CELL_KEYC_F10 = 0x43, CELL_KEYC_F11 = 0x44, CELL_KEYC_F12 = 0x45, CELL_KEYC_PRINTSCREEN = 0x46, CELL_KEYC_SCROLL_LOCK = 0x47, CELL_KEYC_PAUSE = 0x48, CELL_KEYC_INSERT = 0x49, CELL_KEYC_HOME = 0x4a, CELL_KEYC_PAGE_UP = 0x4b, CELL_KEYC_DELETE = 0x4c, CELL_KEYC_END = 0x4d, CELL_KEYC_PAGE_DOWN = 0x4e, CELL_KEYC_RIGHT_ARROW = 0x4f, CELL_KEYC_LEFT_ARROW = 0x50, CELL_KEYC_DOWN_ARROW = 0x51, CELL_KEYC_UP_ARROW = 0x52, CELL_KEYC_NUM_LOCK = 0x53, CELL_KEYC_APPLICATION = 0x65, CELL_KEYC_KANA = 0x88, CELL_KEYC_HENKAN = 0x8a, CELL_KEYC_MUHENKAN = 0x8b, // Raw keycodes for ASCII keys CELL_KEYC_A = 0x04, CELL_KEYC_B = 0x05, CELL_KEYC_C = 0x06, CELL_KEYC_D = 0x07, CELL_KEYC_E = 0x08, CELL_KEYC_F = 0x09, CELL_KEYC_G = 0x0A, CELL_KEYC_H = 0x0B, CELL_KEYC_I = 0x0C, CELL_KEYC_J = 0x0D, CELL_KEYC_K = 0x0E, CELL_KEYC_L = 0x0F, CELL_KEYC_M = 0x10, CELL_KEYC_N = 0x11, CELL_KEYC_O = 0x12, CELL_KEYC_P = 0x13, CELL_KEYC_Q = 0x14, CELL_KEYC_R = 0x15, CELL_KEYC_S = 0x16, CELL_KEYC_T = 0x17, CELL_KEYC_U = 0x18, CELL_KEYC_V = 0x19, CELL_KEYC_W = 0x1A, CELL_KEYC_X = 0x1B, CELL_KEYC_Y = 0x1C, CELL_KEYC_Z = 0x1D, CELL_KEYC_1 = 0x1E, CELL_KEYC_2 = 0x1F, CELL_KEYC_3 = 0x20, CELL_KEYC_4 = 0x21, CELL_KEYC_5 = 0x22, CELL_KEYC_6 = 0x23, CELL_KEYC_7 = 0x24, CELL_KEYC_8 = 0x25, CELL_KEYC_9 = 0x26, CELL_KEYC_0 = 0x27, CELL_KEYC_ENTER = 0x28, CELL_KEYC_ESC = 0x29, CELL_KEYC_BS = 0x2A, CELL_KEYC_TAB = 0x2B, CELL_KEYC_SPACE = 0x2C, CELL_KEYC_MINUS = 0x2D, CELL_KEYC_EQUAL_101 = 0x2E, CELL_KEYC_ACCENT_CIRCONFLEX_106 = 0x2E, CELL_KEYC_LEFT_BRACKET_101 = 0x2F, CELL_KEYC_ATMARK_106 = 0x2F, CELL_KEYC_RIGHT_BRACKET_101 = 0x30, CELL_KEYC_LEFT_BRACKET_106 = 0x30, CELL_KEYC_BACKSLASH_101 = 0x31, CELL_KEYC_RIGHT_BRACKET_106 = 0x32, CELL_KEYC_SEMICOLON = 0x33, CELL_KEYC_QUOTATION_101 = 0x34, CELL_KEYC_COLON_106 = 0x34, CELL_KEYC_COMMA = 0x36, CELL_KEYC_PERIOD = 0x37, CELL_KEYC_SLASH = 0x38, //CELL_KEYC_CAPS_LOCK = 0x39, CELL_KEYC_KPAD_NUMLOCK = 0x53, CELL_KEYC_KPAD_SLASH = 0x54, CELL_KEYC_KPAD_ASTERISK = 0x55, CELL_KEYC_KPAD_MINUS = 0x56, CELL_KEYC_KPAD_PLUS = 0x57, CELL_KEYC_KPAD_ENTER = 0x58, CELL_KEYC_KPAD_1 = 0x59, CELL_KEYC_KPAD_2 = 0x5A, CELL_KEYC_KPAD_3 = 0x5B, CELL_KEYC_KPAD_4 = 0x5C, CELL_KEYC_KPAD_5 = 0x5D, CELL_KEYC_KPAD_6 = 0x5E, CELL_KEYC_KPAD_7 = 0x5F, CELL_KEYC_KPAD_8 = 0x60, CELL_KEYC_KPAD_9 = 0x61, CELL_KEYC_KPAD_0 = 0x62, CELL_KEYC_KPAD_PERIOD = 0x63, CELL_KEYC_BACKSLASH_106 = 0x87, CELL_KEYC_YEN_106 = 0x89, // Made up helper codes (Maybe there's a real code somewhere hidden in the SDK) CELL_KEYC_LESS = 0x90, CELL_KEYC_HASHTAG = 0x91, CELL_KEYC_SSHARP = 0x92, CELL_KEYC_BACK_QUOTE = 0x93 }; enum CellKbMappingType : s32 { CELL_KB_MAPPING_101 = 0, CELL_KB_MAPPING_106 = 1, CELL_KB_MAPPING_106_KANA = 2, CELL_KB_MAPPING_GERMAN_GERMANY = 3, CELL_KB_MAPPING_SPANISH_SPAIN = 4, CELL_KB_MAPPING_FRENCH_FRANCE = 5, CELL_KB_MAPPING_ITALIAN_ITALY = 6, CELL_KB_MAPPING_DUTCH_NETHERLANDS = 7, CELL_KB_MAPPING_PORTUGUESE_PORTUGAL = 8, CELL_KB_MAPPING_RUSSIAN_RUSSIA = 9, CELL_KB_MAPPING_ENGLISH_UK = 10, CELL_KB_MAPPING_KOREAN_KOREA = 11, CELL_KB_MAPPING_NORWEGIAN_NORWAY = 12, CELL_KB_MAPPING_FINNISH_FINLAND = 13, CELL_KB_MAPPING_DANISH_DENMARK = 14, CELL_KB_MAPPING_SWEDISH_SWEDEN = 15, CELL_KB_MAPPING_CHINESE_TRADITIONAL = 16, CELL_KB_MAPPING_CHINESE_SIMPLIFIED = 17, CELL_KB_MAPPING_SWISS_FRENCH_SWITZERLAND = 18, CELL_KB_MAPPING_SWISS_GERMAN_SWITZERLAND = 19, CELL_KB_MAPPING_CANADIAN_FRENCH_CANADA = 20, CELL_KB_MAPPING_BELGIAN_BELGIUM = 21, CELL_KB_MAPPING_POLISH_POLAND = 22, CELL_KB_MAPPING_PORTUGUESE_BRAZIL = 23, CELL_KB_MAPPING_TURKISH_TURKEY = 24 }; u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode);
6,794
C++
.h
197
32.573604
80
0.535996
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,205
GameTablet.h
RPCS3_rpcs3/rpcs3/Emu/Io/GameTablet.h
#pragma once #include "Emu/Io/usb_device.h" class usb_device_gametablet : public usb_device_emulated { public: usb_device_gametablet(u32 controller_index, const std::array<u8, 7>& location); ~usb_device_gametablet(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: u32 m_controller_index; };
502
C++
.h
12
40.083333
146
0.779835
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,206
Skylander.h
RPCS3_rpcs3/rpcs3/Emu/Io/Skylander.h
#pragma once #include "Emu/Io/usb_device.h" #include "Utilities/mutex.h" #include <queue> struct skylander { fs::file sky_file; u8 status = 0; std::queue<u8> queued_status; std::array<u8, 0x40 * 0x10> data{}; u32 last_id = 0; void save(); }; class sky_portal { public: void activate(); void deactivate(); void set_leds(u8 r, u8 g, u8 b); void get_status(u8* buf); void query_block(u8 sky_num, u8 block, u8* reply_buf); void write_block(u8 sky_num, u8 block, const u8* to_write_buf, u8* reply_buf); bool remove_skylander(u8 sky_num); u8 load_skylander(u8* buf, fs::file in_file); protected: shared_mutex sky_mutex; bool activated = true; u8 interrupt_counter = 0; u8 r = 0, g = 0, b = 0; skylander skylanders[8]; }; extern sky_portal g_skyportal; class usb_device_skylander : public usb_device_emulated { public: usb_device_skylander(const std::array<u8, 7>& location); ~usb_device_skylander(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; protected: std::queue<std::array<u8, 32>> q_queries; };
1,232
C++
.h
42
27.47619
146
0.727504
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,207
camera_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/camera_config.h
#pragma once #include "Utilities/Config.h" struct cfg_camera final : cfg::node { cfg_camera(); bool load(); void save() const; struct camera_setting { int width = 0; int height = 0; double min_fps = 0; double max_fps = 0; int format = 0; static constexpr u32 member_count = 5; std::string to_string() const; void from_string(const std::string& text); }; camera_setting get_camera_setting(const std::string& camera, bool& success); void set_camera_setting(const std::string& camera, const camera_setting& setting); const std::string path; cfg::map_entry cameras{ this, "Cameras" }; // <camera>: <width>,<height>,<min_fps>,<max_fps>,<format> }; extern cfg_camera g_cfg_camera;
709
C++
.h
24
27.125
102
0.70901
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,208
music_handler_base.h
RPCS3_rpcs3/rpcs3/Emu/Io/music_handler_base.h
#pragma once #include "util/types.hpp" #include "util/atomic.hpp" class music_handler_base { public: enum class player_status { end_of_media }; virtual ~music_handler_base() = default; virtual void stop() = 0; virtual void pause() = 0; virtual void play(const std::string& path) = 0; virtual void fast_forward(const std::string& path) = 0; virtual void fast_reverse(const std::string& path) = 0; virtual void set_volume(f32 volume) = 0; virtual f32 get_volume() const = 0; s32 get_state() const { return m_state; } void set_status_callback(std::function<void(player_status)> status_callback) { m_status_callback = std::move(status_callback); } protected: atomic_t<s32> m_state{0}; std::function<void(player_status status)> m_status_callback; };
777
C++
.h
30
23.833333
77
0.731081
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,209
topshotelite_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/topshotelite_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class topshotelite_btn { trigger, reload, square, cross, circle, triangle, select, start, l3, r3, ps, dpad_up, dpad_down, dpad_left, dpad_right, ls_x, ls_y, rs_x, rs_y, count }; struct cfg_tse final : public emulated_pad_config<topshotelite_btn> { cfg_tse(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<topshotelite_btn> trigger{this, "Trigger", topshotelite_btn::trigger, pad_button::mouse_button_1}; cfg_pad_btn<topshotelite_btn> reload{this, "Reload", topshotelite_btn::reload, pad_button::mouse_button_2}; cfg_pad_btn<topshotelite_btn> square{this, "Square", topshotelite_btn::square, pad_button::square}; cfg_pad_btn<topshotelite_btn> cross{this, "Cross", topshotelite_btn::cross, pad_button::cross}; cfg_pad_btn<topshotelite_btn> circle{this, "Circle", topshotelite_btn::circle, pad_button::circle}; cfg_pad_btn<topshotelite_btn> triangle{this, "Triangle", topshotelite_btn::triangle, pad_button::triangle}; cfg_pad_btn<topshotelite_btn> select{this, "Select", topshotelite_btn::select, pad_button::select}; cfg_pad_btn<topshotelite_btn> start{this, "Start", topshotelite_btn::start, pad_button::start}; cfg_pad_btn<topshotelite_btn> l3{this, "L3", topshotelite_btn::l3, pad_button::L3}; cfg_pad_btn<topshotelite_btn> r3{this, "R3", topshotelite_btn::r3, pad_button::R3}; cfg_pad_btn<topshotelite_btn> ps{this, "PS", topshotelite_btn::ps, pad_button::ps}; cfg_pad_btn<topshotelite_btn> dpad_up{this, "D-Pad Up", topshotelite_btn::dpad_up, pad_button::dpad_up}; cfg_pad_btn<topshotelite_btn> dpad_down{this, "D-Pad Down", topshotelite_btn::dpad_down, pad_button::dpad_down}; cfg_pad_btn<topshotelite_btn> dpad_left{this, "D-Pad Left", topshotelite_btn::dpad_left, pad_button::dpad_left}; cfg_pad_btn<topshotelite_btn> dpad_right{this, "D-Pad Right", topshotelite_btn::dpad_right, pad_button::dpad_right}; cfg_pad_btn<topshotelite_btn> ls_x{this, "Left Stick X-Axis", topshotelite_btn::ls_x, pad_button::ls_x}; cfg_pad_btn<topshotelite_btn> ls_y{this, "Left Stick Y-Axis", topshotelite_btn::ls_y, pad_button::ls_y}; cfg_pad_btn<topshotelite_btn> rs_x{this, "Right Stick X-Axis", topshotelite_btn::rs_x, pad_button::rs_x}; cfg_pad_btn<topshotelite_btn> rs_y{this, "Right Stick Y-Axis", topshotelite_btn::rs_y, pad_button::rs_y}; }; struct cfg_topshotelite final : public emulated_pads_config<cfg_tse, 4> { cfg_topshotelite() : emulated_pads_config<cfg_tse, 4>("topshotelite") {}; }; extern cfg_topshotelite g_cfg_topshotelite;
2,588
C++
.h
54
46.018519
117
0.740697
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,210
buzz_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/buzz_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class buzz_btn { red, yellow, green, orange, blue, count }; struct cfg_buzzer final : public emulated_pad_config<buzz_btn> { cfg_buzzer(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<buzz_btn> red{ this, "Red", buzz_btn::red, pad_button::R1 }; cfg_pad_btn<buzz_btn> yellow{ this, "Yellow", buzz_btn::yellow, pad_button::cross }; cfg_pad_btn<buzz_btn> green{ this, "Green", buzz_btn::green, pad_button::circle }; cfg_pad_btn<buzz_btn> orange{ this, "Orange", buzz_btn::orange, pad_button::square }; cfg_pad_btn<buzz_btn> blue{ this, "Blue", buzz_btn::blue, pad_button::triangle }; }; struct cfg_buzz final : public emulated_pads_config<cfg_buzzer, 7> { cfg_buzz() : emulated_pads_config<cfg_buzzer, 7>("buzz") {}; }; extern cfg_buzz g_cfg_buzz;
874
C++
.h
26
31.807692
87
0.708333
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,211
camera_handler_base.h
RPCS3_rpcs3/rpcs3/Emu/Io/camera_handler_base.h
#pragma once #include "util/atomic.hpp" #include "util/types.hpp" #include <mutex> class camera_handler_base { public: enum class camera_handler_state { closed, open, running }; virtual ~camera_handler_base() = default; virtual void open_camera() = 0; virtual void close_camera() = 0; virtual void start_camera() = 0; virtual void stop_camera() = 0; virtual void set_format(s32 format, u32 bytes_per_pixel) = 0; virtual void set_frame_rate(u32 frame_rate) = 0; virtual void set_resolution(u32 width, u32 height) = 0; virtual void set_mirrored(bool mirrored) = 0; virtual u64 frame_number() const = 0; // Convenience function to check if there's a new frame. virtual camera_handler_state get_image(u8* buf, u64 size, u32& width, u32& height, u64& frame_number, u64& bytes_read) = 0; camera_handler_state get_state() const { return m_state.load(); }; protected: std::mutex m_mutex; atomic_t<camera_handler_state> m_state = camera_handler_state::closed; bool m_mirrored = false; s32 m_format = 2; // CELL_CAMERA_RAW8 u32 m_bytesize = 0; u32 m_width = 640; u32 m_height = 480; u32 m_frame_rate = 30; };
1,137
C++
.h
35
30.4
124
0.725526
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,212
Infinity.h
RPCS3_rpcs3/rpcs3/Emu/Io/Infinity.h
#pragma once #include "Emu/Io/usb_device.h" #include "Utilities/mutex.h" #include <array> #include <queue> struct infinity_figure { fs::file inf_file; std::array<u8, 0x14 * 0x10> data{}; bool present = false; u8 order_added = 255; void save(); }; class infinity_base { public: void get_blank_response(u8 sequence, std::array<u8, 32>& reply_buf); void descramble_and_seed(u8* buf, u8 sequence, std::array<u8, 32>& reply_buf); void get_next_and_scramble(u8 sequence, std::array<u8, 32>& reply_buf); void get_present_figures(u8 sequence, std::array<u8, 32>& reply_buf); void query_block(u8 fig_num, u8 block, std::array<u8, 32>& reply_buf, u8 sequence); void write_block(u8 fig_num, u8 block, const u8* to_write_buf, std::array<u8, 32>& reply_buf, u8 sequence); void get_figure_identifier(u8 fig_num, u8 sequence, std::array<u8, 32>& reply_buf); bool has_figure_been_added_removed() const; std::array<u8, 32> pop_added_removed_response(); bool remove_figure(u8 position); u32 load_figure(const std::array<u8, 0x14 * 0x10>& buf, fs::file in_file, u8 position); protected: shared_mutex infinity_mutex; std::array<infinity_figure, 9> figures; private: u8 generate_checksum(const std::array<u8, 32>& data, int num_of_bytes) const; u32 descramble(u64 num_to_descramble); u64 scramble(u32 num_to_scramble, u32 garbage); void generate_seed(u32 seed); u32 get_next(); infinity_figure& get_figure_by_order(u8 order_added); u8 derive_figure_position(u8 position); u32 random_a; u32 random_b; u32 random_c; u32 random_d; u8 m_figure_order = 0; std::queue<std::array<u8, 32>> m_figure_added_removed_responses; }; extern infinity_base g_infinitybase; class usb_device_infinity : public usb_device_emulated { public: usb_device_infinity(const std::array<u8, 7>& location); ~usb_device_infinity(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; protected: std::queue<std::array<u8, 32>> m_queries; };
2,124
C++
.h
56
36.071429
146
0.742218
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,213
pad_config_types.h
RPCS3_rpcs3/rpcs3/Emu/Io/pad_config_types.h
#pragma once #include "util/types.hpp" enum class pad_handler { null, keyboard, ds3, ds4, dualsense, skateboard, #ifdef _WIN32 xinput, mm, #endif #ifdef HAVE_SDL2 sdl, #endif #ifdef HAVE_LIBEVDEV evdev, #endif }; enum class mouse_movement_mode : s32 { relative = 0, absolute = 1 }; struct PadInfo { u32 now_connect = 0; u32 system_info = 0; bool ignore_input = false; };
390
C++
.h
32
10.59375
36
0.745763
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,214
RB3MidiGuitar.h
RPCS3_rpcs3/rpcs3/Emu/Io/RB3MidiGuitar.h
#pragma once #include "Emu/Io/usb_device.h" #include <rtmidi_c.h> class usb_device_rb3_midi_guitar : public usb_device_emulated { private: usz response_pos = 0; bool buttons_enabled = false; RtMidiInPtr midi_in{}; // button states struct { u8 count = 0; bool cross = false; bool circle = false; bool square = false; bool triangle = false; bool start = false; bool select = false; bool tilt_sensor = false; bool sustain_pedal = false; // used for overdrive u8 dpad = 8; std::array<u8, 6> frets{}; std::array<u8, 6> string_velocities{}; } button_state; void parse_midi_message(u8* msg, usz size); void write_state(u8* buf); public: usb_device_rb3_midi_guitar(const std::array<u8, 7>& location, const std::string& device_name, bool twentytwo_fret); ~usb_device_rb3_midi_guitar(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; };
1,068
C++
.h
33
29.909091
146
0.728516
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,215
turntable_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/turntable_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class turntable_btn { red, green, blue, dpad_up, dpad_down, dpad_left, dpad_right, start, select, square, circle, cross, triangle, right_turntable, crossfader, effects_dial, count }; struct cfg_turntable final : public emulated_pad_config<turntable_btn> { cfg_turntable(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<turntable_btn> blue{ this, "Blue", turntable_btn::blue, pad_button::square }; cfg_pad_btn<turntable_btn> green{ this, "Green", turntable_btn::green, pad_button::cross }; cfg_pad_btn<turntable_btn> red{ this, "Red", turntable_btn::red, pad_button::circle }; cfg_pad_btn<turntable_btn> dpad_up{ this, "D-Pad Up", turntable_btn::dpad_up, pad_button::dpad_up }; cfg_pad_btn<turntable_btn> dpad_down{ this, "D-Pad Down", turntable_btn::dpad_down, pad_button::dpad_down }; cfg_pad_btn<turntable_btn> dpad_left{ this, "D-Pad Left", turntable_btn::dpad_left, pad_button::dpad_left }; cfg_pad_btn<turntable_btn> dpad_right{ this, "D-Pad Right", turntable_btn::dpad_right, pad_button::dpad_right }; cfg_pad_btn<turntable_btn> start{ this, "Start", turntable_btn::start, pad_button::start }; cfg_pad_btn<turntable_btn> select{ this, "Select", turntable_btn::select, pad_button::select }; cfg_pad_btn<turntable_btn> square{ this, "Square", turntable_btn::square, pad_button::R2 }; cfg_pad_btn<turntable_btn> circle{ this, "Circle", turntable_btn::circle, pad_button::L1 }; cfg_pad_btn<turntable_btn> cross{ this, "Cross", turntable_btn::cross, pad_button::R1 }; cfg_pad_btn<turntable_btn> triangle{ this, "Triangle", turntable_btn::triangle, pad_button::triangle }; cfg_pad_btn<turntable_btn> right_turntable{ this, "Right Turntable", turntable_btn::right_turntable, pad_button::ls_y }; cfg_pad_btn<turntable_btn> crossfader{ this, "Crossfader", turntable_btn::crossfader, pad_button::rs_y }; cfg_pad_btn<turntable_btn> effects_dial{ this, "Effects Dial", turntable_btn::effects_dial, pad_button::rs_x }; }; struct cfg_turntables final : public emulated_pads_config<cfg_turntable, 2> { cfg_turntables() : emulated_pads_config<cfg_turntable, 2>("turntable") {}; }; extern cfg_turntables g_cfg_turntable;
2,260
C++
.h
48
45.1875
121
0.733212
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,216
midi_config_types.h
RPCS3_rpcs3/rpcs3/Emu/Io/midi_config_types.h
#pragma once #include <string> static constexpr usz max_midi_devices = 3; enum class midi_device_type { keyboard, guitar, guitar_22fret, drums, }; struct midi_device { midi_device_type type{}; std::string name; static midi_device from_string(const std::string& str); };
282
C++
.h
16
15.875
56
0.766284
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,217
GHLtar.h
RPCS3_rpcs3/rpcs3/Emu/Io/GHLtar.h
#pragma once #include "Emu/Io/usb_device.h" class usb_device_ghltar : public usb_device_emulated { public: usb_device_ghltar(u32 controller_index, const std::array<u8, 7>& location); ~usb_device_ghltar(); void control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, u32 buf_size, u8* buf, UsbTransfer* transfer) override; void interrupt_transfer(u32 buf_size, u8* buf, u32 endpoint, UsbTransfer* transfer) override; private: u32 m_controller_index; };
490
C++
.h
12
39.083333
146
0.774262
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,218
guncon3_config.h
RPCS3_rpcs3/rpcs3/Emu/Io/guncon3_config.h
#pragma once #include "emulated_pad_config.h" #include <array> enum class guncon3_btn { trigger, a1, a2, a3, b1, b2, b3, c1, c2, as_x, as_y, bs_x, bs_y, count }; struct cfg_gc3 final : public emulated_pad_config<guncon3_btn> { cfg_gc3(node* owner, const std::string& name) : emulated_pad_config(owner, name) {} cfg_pad_btn<guncon3_btn> trigger{this, "Trigger", guncon3_btn::trigger, pad_button::cross}; cfg_pad_btn<guncon3_btn> a1{this, "A1", guncon3_btn::a1, pad_button::L1}; cfg_pad_btn<guncon3_btn> a2{this, "A2", guncon3_btn::a2, pad_button::L2}; cfg_pad_btn<guncon3_btn> a3{this, "A3", guncon3_btn::a3, pad_button::L3}; cfg_pad_btn<guncon3_btn> b1{this, "B1", guncon3_btn::b1, pad_button::R1}; cfg_pad_btn<guncon3_btn> b2{this, "B2", guncon3_btn::b2, pad_button::R2}; cfg_pad_btn<guncon3_btn> b3{this, "B3", guncon3_btn::b3, pad_button::R3}; cfg_pad_btn<guncon3_btn> c1{this, "C1", guncon3_btn::c1, pad_button::select}; cfg_pad_btn<guncon3_btn> c2{this, "C2", guncon3_btn::c2, pad_button::start}; cfg_pad_btn<guncon3_btn> as_x{this, "A-stick X-Axis", guncon3_btn::as_x, pad_button::ls_x}; cfg_pad_btn<guncon3_btn> as_y{this, "A-stick Y-Axis", guncon3_btn::as_y, pad_button::ls_y}; cfg_pad_btn<guncon3_btn> bs_x{this, "B-stick X-Axis", guncon3_btn::bs_x, pad_button::rs_x}; cfg_pad_btn<guncon3_btn> bs_y{this, "B-stick Y-Axis", guncon3_btn::bs_y, pad_button::rs_y}; }; struct cfg_guncon3 final : public emulated_pads_config<cfg_gc3, 4> { cfg_guncon3() : emulated_pads_config<cfg_gc3, 4>("guncon3") {}; }; extern cfg_guncon3 g_cfg_guncon3;
1,580
C++
.h
42
35.738095
92
0.692157
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
6,219
null_music_handler.h
RPCS3_rpcs3/rpcs3/Emu/Io/Null/null_music_handler.h
#pragma once #include "Emu/Io/music_handler_base.h" class null_music_handler final : public music_handler_base { public: null_music_handler() : music_handler_base() {} void stop() override { m_state = 0; } // CELL_MUSIC_PB_STATUS_STOP void pause() override { m_state = 2; } // CELL_MUSIC_PB_STATUS_PAUSE void play(const std::string& /*path*/) override { m_state = 1; } // CELL_MUSIC_PB_STATUS_PLAY void fast_forward(const std::string& /*path*/) override { m_state = 3; } // CELL_MUSIC_PB_STATUS_FASTFORWARD void fast_reverse(const std::string& /*path*/) override { m_state = 4; } // CELL_MUSIC_PB_STATUS_FASTREVERSE void set_volume(f32 volume) override { m_volume = volume; } f32 get_volume() const override { return m_volume; } private: atomic_t<f32> m_volume{0.0f}; };
784
C++
.h
16
47.1875
109
0.70288
RPCS3/rpcs3
15,204
1,895
1,021
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false