From 2ccfee2e45372c8de1d07a80e9d3320bdc908481 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Mon, 9 Jan 2023 13:08:08 +0300 Subject: [PATCH] rsx: Propagate decode failures up the chain. - Dumping invalid data should not crash --- rpcs3/Emu/RSX/gcm_enums.h | 10 ++++- rpcs3/Emu/RSX/rsx_decode.h | 90 ++++++++++++++++++------------------- rpcs3/Emu/RSX/rsx_methods.h | 2 +- 3 files changed, 55 insertions(+), 47 deletions(-) diff --git a/rpcs3/Emu/RSX/gcm_enums.h b/rpcs3/Emu/RSX/gcm_enums.h index d584123b6e..7dd20e7e1a 100644 --- a/rpcs3/Emu/RSX/gcm_enums.h +++ b/rpcs3/Emu/RSX/gcm_enums.h @@ -1112,11 +1112,19 @@ namespace rsx enum class surface_raster_type : u8 { - undefined = CELL_GCM_ZERO, + undefined = CELL_GCM_ZERO, // TODO: Drop this (used in surface cache for optional args) linear = CELL_GCM_SURFACE_PITCH, swizzle = CELL_GCM_SURFACE_SWIZZLE, }; + static inline auto to_surface_raster_type(u32 in) + { + return gcm_enum_cast< + surface_raster_type, + CELL_GCM_SURFACE_PITCH, + CELL_GCM_SURFACE_SWIZZLE>(in); + } + enum class surface_antialiasing : u8 { center_1_sample = CELL_GCM_SURFACE_CENTER_1, diff --git a/rpcs3/Emu/RSX/rsx_decode.h b/rpcs3/Emu/RSX/rsx_decode.h index c041ae4161..bdf0c4aabd 100644 --- a/rpcs3/Emu/RSX/rsx_decode.h +++ b/rpcs3/Emu/RSX/rsx_decode.h @@ -2222,7 +2222,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::comparison_function depth_func() const + auto depth_func() const { return to_comparison_function(value); } @@ -2245,7 +2245,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::comparison_function stencil_func() const + auto stencil_func() const { return to_comparison_function(value); } @@ -2268,7 +2268,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::comparison_function back_stencil_func() const + auto back_stencil_func() const { return to_comparison_function(value); } @@ -2291,7 +2291,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::comparison_function alpha_func() const + auto alpha_func() const { return to_comparison_function(value); } @@ -2314,7 +2314,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::stencil_op fail() const + auto fail() const { return to_stencil_op(value); } @@ -2337,7 +2337,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::stencil_op zfail() const + auto zfail() const { return to_stencil_op(value); } @@ -2360,7 +2360,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::stencil_op zpass() const + auto zpass() const { return to_stencil_op(value); } @@ -2383,7 +2383,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::stencil_op back_fail() const + auto back_fail() const { return to_stencil_op(value); } @@ -2406,7 +2406,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::stencil_op back_zfail() const + auto back_zfail() const { return to_stencil_op(value); } @@ -2429,7 +2429,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - rsx::stencil_op back_zpass() const + auto back_zpass() const { return to_stencil_op(value); } @@ -2650,7 +2650,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - logic_op logic_operation() const + auto logic_operation() const { return to_logic_op(value); } @@ -2673,7 +2673,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - front_face front_face_mode() const + auto front_face_mode() const { return to_front_face(value); } @@ -2720,7 +2720,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - surface_target target() const + auto target() const { return to_surface_target(value); } @@ -2743,7 +2743,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - fog_mode fog_equation() const + auto fog_equation() const { return to_fog_mode(value); } @@ -2766,7 +2766,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - primitive_type primitive() const + auto primitive() const { return to_primitive_type(value); } @@ -2789,7 +2789,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - blit_engine::transfer_operation transfer_op() const + auto transfer_op() const { return blit_engine::to_transfer_operation(value); } @@ -2812,7 +2812,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - expected transfer_source_fmt() const + auto transfer_source_fmt() const { return blit_engine::to_transfer_source_format(value); } @@ -2835,7 +2835,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - blit_engine::context_surface ctx_surface() const + auto ctx_surface() const { return blit_engine::to_context_surface(value); } @@ -2858,7 +2858,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - expected transfer_dest_fmt() const + auto transfer_dest_fmt() const { return blit_engine::to_transfer_destination_format(value); } @@ -2890,12 +2890,12 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - blend_equation blend_rgb() const + auto blend_rgb() const { return to_blend_equation(blend_rgb_raw()); } - blend_equation blend_a() const + auto blend_a() const { return to_blend_equation(blend_a_raw()); } @@ -2927,12 +2927,12 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - blend_factor src_blend_rgb() const + auto src_blend_rgb() const { return to_blend_factor(src_blend_rgb_raw()); } - blend_factor src_blend_a() const + auto src_blend_a() const { return to_blend_factor(src_blend_a_raw()); } @@ -2964,12 +2964,12 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - blend_factor dst_blend_rgb() const + auto dst_blend_rgb() const { return to_blend_factor(dst_blend_rgb_raw()); } - blend_factor dst_blend_a() const + auto dst_blend_a() const { return to_blend_factor(dst_blend_a_raw()); } @@ -3095,12 +3095,12 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - window_origin window_shader_origin() const + auto window_shader_origin() const { return to_window_origin(window_shader_origin_raw()); } - window_pixel_center window_shader_pixel_center() const + auto window_shader_pixel_center() const { return to_window_pixel_center(window_shader_pixel_center_raw()); } @@ -3172,32 +3172,32 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - user_clip_plane_op clip_plane0() const + auto clip_plane0() const { return to_user_clip_plane_op(clip_plane0_raw()); } - user_clip_plane_op clip_plane1() const + auto clip_plane1() const { return to_user_clip_plane_op(clip_plane1_raw()); } - user_clip_plane_op clip_plane2() const + auto clip_plane2() const { return to_user_clip_plane_op(clip_plane2_raw()); } - user_clip_plane_op clip_plane3() const + auto clip_plane3() const { return to_user_clip_plane_op(clip_plane3_raw()); } - user_clip_plane_op clip_plane4() const + auto clip_plane4() const { return to_user_clip_plane_op(clip_plane4_raw()); } - user_clip_plane_op clip_plane5() const + auto clip_plane5() const { return to_user_clip_plane_op(clip_plane5_raw()); } @@ -3306,22 +3306,22 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - surface_color_format color_fmt() const + auto color_fmt() const { return to_surface_color_format(color_fmt_raw()); } - surface_depth_format depth_fmt() const + auto depth_fmt() const { return to_surface_depth_format(depth_fmt_raw()); } - surface_raster_type type() const + auto type() const { - return static_cast(type_raw()); + return to_surface_raster_type(type_raw()); } - surface_antialiasing antialias() const + auto antialias() const { return to_surface_antialiasing(antialias_raw()); } @@ -3657,7 +3657,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - blit_engine::context_dma context_dma_report() const + auto context_dma_report() const { return blit_engine::to_context_dma(value); } @@ -3711,12 +3711,12 @@ struct registers_decoder return bf_decoder<0, 16>(value); } - blit_engine::transfer_origin transfer_origin() const + auto transfer_origin() const { return blit_engine::to_transfer_origin(transfer_origin_raw()); } - blit_engine::transfer_interpolator transfer_interpolator() const + auto transfer_interpolator() const { return blit_engine::to_transfer_interpolator(transfer_interpolator_raw()); } @@ -3741,7 +3741,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - expected format() const + auto format() const { return blit_engine::to_transfer_destination_format(transfer_destination_fmt()); } @@ -4011,7 +4011,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - shading_mode shading() const + auto shading() const { return to_shading_mode(value); } @@ -4034,7 +4034,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - polygon_mode front_polygon_mode() const + auto front_polygon_mode() const { return to_polygon_mode(value); } @@ -4057,7 +4057,7 @@ struct registers_decoder public: decoded_type(u32 value) : value(value) {} - polygon_mode back_polygon_mode() const + auto back_polygon_mode() const { return to_polygon_mode(value); } diff --git a/rpcs3/Emu/RSX/rsx_methods.h b/rpcs3/Emu/RSX/rsx_methods.h index 7972d46f3d..6896fca2eb 100644 --- a/rpcs3/Emu/RSX/rsx_methods.h +++ b/rpcs3/Emu/RSX/rsx_methods.h @@ -1262,7 +1262,7 @@ namespace rsx surface_depth_format2 surface_depth_fmt() const { - const auto base_fmt = decode().depth_fmt(); + const auto base_fmt = *decode().depth_fmt(); if (!depth_buffer_float_enabled()) [[likely]] { return static_cast(base_fmt);