From 7dae376646211752fceb68262dc7e867295f9602 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 19 Apr 2021 11:11:24 +0300 Subject: [PATCH] Implement fill_array() utility --- rpcs3/Emu/GDB.cpp | 6 +-- rpcs3/Emu/GDB.h | 2 +- rpcs3/Emu/IdManager.h | 4 +- rpcs3/Emu/RSX/Capture/rsx_replay.h | 17 ++++--- .../Overlays/Shaders/shader_loading_dialog.h | 5 +- .../Shaders/shader_loading_dialog_native.h | 2 +- rpcs3/Emu/RSX/RSXFragmentProgram.h | 7 ++- rpcs3/Emu/RSX/RSXOffload.h | 3 ++ rpcs3/Emu/RSX/RSXTexture.h | 18 +++++-- rpcs3/Emu/RSX/RSXThread.h | 6 +-- rpcs3/Emu/RSX/rsx_methods.h | 32 ++++++------ rpcs3/Emu/RSX/rsx_vertex_data.h | 6 +-- rpcs3/cmake_modules/ConfigureCompiler.cmake | 1 + rpcs3/util/auto_typemap.hpp | 4 +- rpcs3/util/fixed_typemap.hpp | 6 +-- rpcs3/util/shared_ptr.hpp | 6 +-- rpcs3/util/types.hpp | 51 +++++++++++++++---- 17 files changed, 111 insertions(+), 65 deletions(-) diff --git a/rpcs3/Emu/GDB.cpp b/rpcs3/Emu/GDB.cpp index 51b0583ed9..c7b9805265 100644 --- a/rpcs3/Emu/GDB.cpp +++ b/rpcs3/Emu/GDB.cpp @@ -63,9 +63,9 @@ void set_nonblocking(int s) struct gdb_cmd { - std::string cmd; - std::string data; - u8 checksum; + std::string cmd{}; + std::string data{}; + u8 checksum{}; }; bool check_errno_again() diff --git a/rpcs3/Emu/GDB.h b/rpcs3/Emu/GDB.h index 2e79216600..e67d505e7d 100644 --- a/rpcs3/Emu/GDB.h +++ b/rpcs3/Emu/GDB.h @@ -16,7 +16,7 @@ class gdb_thread int server_socket = -1; int client_socket = -1; - std::weak_ptr selected_thread; + std::weak_ptr selected_thread{}; u64 continue_ops_thread_id = ANY_THREAD; u64 general_ops_thread_id = ANY_THREAD; diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index 61434f5a81..673f1c0beb 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -141,8 +141,8 @@ namespace id_manager template struct id_map { - std::vector>> vec; - shared_mutex mutex; // TODO: Use this instead of global mutex + std::vector>> vec{}; + shared_mutex mutex{}; // TODO: Use this instead of global mutex id_map() { diff --git a/rpcs3/Emu/RSX/Capture/rsx_replay.h b/rpcs3/Emu/RSX/Capture/rsx_replay.h index 2fc3d3d177..388b241d19 100644 --- a/rpcs3/Emu/RSX/Capture/rsx_replay.h +++ b/rpcs3/Emu/RSX/Capture/rsx_replay.h @@ -14,7 +14,8 @@ namespace rsx { struct memory_block_data { - std::vector data; + std::vector data{}; + template void serialize(Archive& ar) { @@ -96,8 +97,8 @@ namespace rsx // bleh, may need to break these out, might be unnecessary to do both always struct tile_state { - tile_info tiles[15]; - zcull_info zculls[8]; + tile_info tiles[15]{}; + zcull_info zculls[8]{}; template void serialize(Archive & ar) @@ -126,7 +127,7 @@ namespace rsx struct display_buffers_state { - std::array buffers; + std::array buffers{}; u32 count{0}; template @@ -195,12 +196,12 @@ namespace rsx { u64 tile_hash{0}; u64 display_buffer_hash{0}; - frame_capture_data::display_buffers_state buffer_state; - frame_capture_data::tile_state tile_state; + frame_capture_data::display_buffers_state buffer_state{}; + frame_capture_data::tile_state tile_state{}; }; - u32 user_mem_addr; - current_state cs; + u32 user_mem_addr{}; + current_state cs{}; std::unique_ptr frame; public: diff --git a/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog.h b/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog.h index 3b25c25a87..7d141c49d2 100644 --- a/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog.h +++ b/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog.h @@ -6,9 +6,10 @@ namespace rsx { struct shader_loading_dialog { - std::shared_ptr dlg; - atomic_t ref_cnt; + std::shared_ptr dlg{}; + atomic_t ref_cnt{0}; + virtual ~shader_loading_dialog() = default; virtual void create(const std::string& msg, const std::string& title); virtual void update_msg(u32 index, const std::string& msg); virtual void inc_value(u32 index, u32 value); diff --git a/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog_native.h b/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog_native.h index 4ac76805d3..08ad43bfcf 100644 --- a/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog_native.h +++ b/rpcs3/Emu/RSX/Overlays/Shaders/shader_loading_dialog_native.h @@ -16,7 +16,7 @@ namespace rsx struct shader_loading_dialog_native : rsx::shader_loading_dialog { rsx::thread* owner = nullptr; - std::shared_ptr dlg; + std::shared_ptr dlg{}; shader_loading_dialog_native(GSRender* ptr); diff --git a/rpcs3/Emu/RSX/RSXFragmentProgram.h b/rpcs3/Emu/RSX/RSXFragmentProgram.h index 9c89dff266..91f07bff1b 100644 --- a/rpcs3/Emu/RSX/RSXFragmentProgram.h +++ b/rpcs3/Emu/RSX/RSXFragmentProgram.h @@ -231,7 +231,7 @@ struct RSXFragmentProgram struct data_storage_helper { void* data_ptr = nullptr; - std::vector local_storage; + std::vector local_storage{}; data_storage_helper() = default; @@ -292,7 +292,7 @@ struct RSXFragmentProgram } } - } mutable data; + } mutable data{}; u32 offset = 0; u32 ucode_length = 0; @@ -305,7 +305,7 @@ struct RSXFragmentProgram u32 texture_dimensions = 0; u32 texcoord_control_mask = 0; - float texture_scale[16][4]; + float texture_scale[16][4]{}; bool valid = false; @@ -327,7 +327,6 @@ struct RSXFragmentProgram RSXFragmentProgram() { - std::memset(texture_scale, 0, sizeof(float) * 16 * 4); } static RSXFragmentProgram clone(const RSXFragmentProgram& prog) diff --git a/rpcs3/Emu/RSX/RSXOffload.h b/rpcs3/Emu/RSX/RSXOffload.h index 986c29bbd2..f8b12194ce 100644 --- a/rpcs3/Emu/RSX/RSXOffload.h +++ b/rpcs3/Emu/RSX/RSXOffload.h @@ -43,6 +43,9 @@ namespace rsx transport_packet(u32 command, void* args) : type(op::callback), src(args), aux_param0(command) {} + + transport_packet(const transport_packet&) = delete; + transport_packet& operator=(const transport_packet&) = delete; }; atomic_t m_mem_fault_flag = false; diff --git a/rpcs3/Emu/RSX/RSXTexture.h b/rpcs3/Emu/RSX/RSXTexture.h index d7db20488b..e4d58cec6d 100644 --- a/rpcs3/Emu/RSX/RSXTexture.h +++ b/rpcs3/Emu/RSX/RSXTexture.h @@ -7,10 +7,15 @@ namespace rsx { protected: const u8 m_index; - std::array ®isters; + std::array& registers; public: - fragment_texture(u8 idx, std::array &r) : m_index(idx), registers(r) { } + fragment_texture(u8 idx, std::array& r) + : m_index(idx) + , registers(r) + { + } + fragment_texture() = delete; // Offset @@ -87,10 +92,15 @@ namespace rsx { protected: const u8 m_index; - std::array ®isters; + std::array& registers; public: - vertex_texture(u8 idx, std::array &r) : m_index(idx), registers(r) { } + vertex_texture(u8 idx, std::array &r) + : m_index(idx) + , registers(r) + { + } + vertex_texture() = delete; // Offset diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index 216ecaa467..d42ce67c35 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -40,12 +40,12 @@ namespace rsx { std::array, 4096> ea; std::array, 4096> io; - std::array rs; + std::array rs{}; rsx_iomap_table() noexcept + : ea(fill_array(-1)) + , io(fill_array(-1)) { - std::memset(ea.data(), -1, sizeof(ea)); - std::memset(io.data(), -1, sizeof(io)); } // Try to get the real address given a mapped address diff --git a/rpcs3/Emu/RSX/rsx_methods.h b/rpcs3/Emu/RSX/rsx_methods.h index 37b1fcdb51..2278d8ec60 100644 --- a/rpcs3/Emu/RSX/rsx_methods.h +++ b/rpcs3/Emu/RSX/rsx_methods.h @@ -63,16 +63,16 @@ namespace rsx class draw_clause { // Stores the first and count argument from draw/draw indexed parameters between begin/end clauses. - simple_array draw_command_ranges; + simple_array draw_command_ranges{}; // Stores rasterization barriers for primitive types sensitive to adjacency - simple_array draw_command_barriers; + simple_array draw_command_barriers{}; // Counter used to parse the commands in order - u32 current_range_index; + u32 current_range_index{}; // Location of last execution barrier - u32 last_execution_barrier_index; + u32 last_execution_barrier_index{}; // Helper functions // Add a new draw command @@ -102,14 +102,14 @@ namespace rsx } public: - primitive_type primitive; - draw_command command; + 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_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 - simple_array inline_vertex_array; + simple_array inline_vertex_array{}; void insert_command_barrier(command_barrier_type type, u32 arg) { @@ -457,8 +457,8 @@ namespace rsx struct rsx_state { public: - std::array registers; - u32 register_previous_value; + std::array registers{}; + u32 register_previous_value{}; template using decoded_type = typename registers_decoder::decoded_type; @@ -492,10 +492,10 @@ namespace rsx std::array vertex_textures; - std::array transform_program; - std::array transform_constants; + std::array transform_program{}; + std::array transform_constants{}; - draw_clause current_draw_clause; + draw_clause current_draw_clause{}; /** * RSX can sources vertex attributes from 2 places: @@ -514,7 +514,7 @@ namespace rsx * Note that behavior when both vertex array and immediate value system are disabled but vertex attrib mask * request inputs is unknown. */ - std::array register_vertex_info; + std::array register_vertex_info{}; std::array vertex_arrays_info; private: diff --git a/rpcs3/Emu/RSX/rsx_vertex_data.h b/rpcs3/Emu/RSX/rsx_vertex_data.h index 76acf24e71..7e9e59197c 100644 --- a/rpcs3/Emu/RSX/rsx_vertex_data.h +++ b/rpcs3/Emu/RSX/rsx_vertex_data.h @@ -23,8 +23,8 @@ private: public: data_array_format_info(int id, std::array& r) - : index(id) - , registers(r) + : index(id) + , registers(r) { } @@ -124,7 +124,7 @@ struct register_vertex_data_info vertex_base_type type = vertex_base_type::f; register_vertex_data_info() = default; - std::array data; + std::array data{}; }; } diff --git a/rpcs3/cmake_modules/ConfigureCompiler.cmake b/rpcs3/cmake_modules/ConfigureCompiler.cmake index 58b0e2b235..e4cb934010 100644 --- a/rpcs3/cmake_modules/ConfigureCompiler.cmake +++ b/rpcs3/cmake_modules/ConfigureCompiler.cmake @@ -48,6 +48,7 @@ else() #add_compile_options(-Wpadded) add_compile_options(-Wempty-body) add_compile_options(-Wredundant-decls) + #add_compile_options(-Weffc++) add_compile_options(-Wstrict-aliasing=1) #add_compile_options(-Wnull-dereference) diff --git a/rpcs3/util/auto_typemap.hpp b/rpcs3/util/auto_typemap.hpp index e1ef056edb..fba32e74a7 100644 --- a/rpcs3/util/auto_typemap.hpp +++ b/rpcs3/util/auto_typemap.hpp @@ -15,8 +15,8 @@ namespace stx // Save default constructor and destructor struct typeinfo { - bool(*create)(uchar* ptr, auto_typemap&) noexcept; - void(*destroy)(void* ptr) noexcept; + bool(*create)(uchar* ptr, auto_typemap&) noexcept = nullptr; + void(*destroy)(void* ptr) noexcept = nullptr; template static bool call_ctor(uchar* ptr, auto_typemap& _this) noexcept diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index 674228e7b7..09618ed4f0 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -56,9 +56,9 @@ namespace stx // Save default constructor and destructor struct typeinfo { - bool(*create)(uchar* ptr, manual_typemap&) noexcept; - void(*destroy)(void* ptr) noexcept; - std::string_view name; + bool(*create)(uchar* ptr, manual_typemap&) noexcept = nullptr; + void(*destroy)(void* ptr) noexcept = nullptr; + std::string_view name{}; template static bool call_ctor(uchar* ptr, manual_typemap& _this) noexcept diff --git a/rpcs3/util/shared_ptr.hpp b/rpcs3/util/shared_ptr.hpp index ad4cac258e..8d2c368cef 100644 --- a/rpcs3/util/shared_ptr.hpp +++ b/rpcs3/util/shared_ptr.hpp @@ -113,7 +113,7 @@ namespace stx class alignas(T) shared_data final : align_filler { public: - shared_counter m_ctr; + shared_counter m_ctr{}; T m_data; @@ -128,9 +128,9 @@ namespace stx class alignas(T) shared_data final : align_filler { public: - usz m_count; + usz m_count{}; - shared_counter m_ctr; + shared_counter m_ctr{}; constexpr shared_data() noexcept = default; }; diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index e88697ab0a..46469cca3c 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -7,6 +7,7 @@ #include #include #include +#include using std::chrono::steady_clock; @@ -457,16 +458,16 @@ constexpr inline struct umax_helper { constexpr umax_helper() noexcept = default; - template , typename = std::enable_if_t>> - constexpr bool operator==(const T& rhs) const + template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) + friend constexpr bool operator==(const umax_helper&, const T& rhs) { - return rhs == static_cast(-1); + return rhs == static_cast>(-1); } #if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__ #else - template - friend constexpr std::enable_if_t>, bool> operator==(const T& lhs, const umax_helper&) + template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) + friend constexpr bool operator==(const T& lhs, const umax_helper&) { return lhs == static_cast>(-1); } @@ -474,14 +475,14 @@ constexpr inline struct umax_helper #if __cpp_impl_three_way_comparison >= 201711 #else - template , typename = std::enable_if_t>> - constexpr bool operator!=(const T& rhs) const + template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) + friend constexpr bool operator!=(const umax_helper&, const T& rhs) { - return rhs != static_cast(-1); + return rhs != static_cast>(-1); } - template - friend constexpr std::enable_if_t>, bool> operator!=(const T& lhs, const umax_helper&) + template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) + friend constexpr bool operator!=(const T& lhs, const umax_helper&) { return lhs != static_cast>(-1); } @@ -767,3 +768,33 @@ struct value_hash return static_cast(value) >> Shift; } }; + +template +struct fill_array_t +{ + std::tuple args; + + template + constexpr std::unwrap_reference_t get() const + { + return std::get(args); + } + + template + constexpr std::array fill(std::index_sequence, std::index_sequence) const + { + return{(static_cast(Idx), U(get()...))...}; + } + + template + constexpr operator std::array() const + { + return fill(std::make_index_sequence(), std::make_index_sequence()); + } +}; + +template +constexpr auto fill_array(const T&... args) +{ + return fill_array_t{{args...}}; +}