From 074f19ca907f03c189c1c3aaafb2e854e89279d7 Mon Sep 17 00:00:00 2001 From: reallibretroadmin Date: Sun, 8 Jan 2023 05:48:06 +0100 Subject: [PATCH] (Metal) Cleanups --- gfx/common/metal/metal_common.h | 10 +-- gfx/common/metal/metal_renderer.m | 63 +++++++------------ .../RetroArch_Metal.xcodeproj/project.pbxproj | 16 ----- 3 files changed, 24 insertions(+), 65 deletions(-) diff --git a/gfx/common/metal/metal_common.h b/gfx/common/metal/metal_common.h index be4fa5a9d7..ee6bc732b7 100644 --- a/gfx/common/metal/metal_common.h +++ b/gfx/common/metal/metal_common.h @@ -53,7 +53,7 @@ typedef NS_ENUM(NSUInteger, RPixelFormat) RPixelFormatBGRA8Unorm, RPixelFormatBGRX8Unorm, /* RetroArch XRGB */ - RPixelFormatCount, + RPixelFormatCount }; extern NSUInteger RPixelFormatToBPP(RPixelFormat format); @@ -62,14 +62,10 @@ typedef NS_ENUM(NSUInteger, RTextureFilter) { RTextureFilterNearest, RTextureFilterLinear, - - RTextureFilterCount, + RTextureFilterCount }; extern matrix_float4x4 matrix_proj_ortho(float left, float right, float top, float bottom); -extern matrix_float4x4 matrix_rotate_z(float rot); -extern matrix_float4x4 make_matrix_float4x4(const float *v); - @interface Texture : NSObject @@ -189,7 +185,7 @@ typedef NS_ENUM(NSInteger, ViewDrawState) ViewDrawStateContext = 0x01, ViewDrawStateEncoder = 0x02, - ViewDrawStateAll = 0x03, + ViewDrawStateAll = 0x03 }; @interface ViewDescriptor : NSObject diff --git a/gfx/common/metal/metal_renderer.m b/gfx/common/metal/metal_renderer.m index dc218baa81..ad6246c890 100644 --- a/gfx/common/metal/metal_renderer.m +++ b/gfx/common/metal/metal_renderer.m @@ -63,7 +63,7 @@ static NSString *NSStringFromRPixelFormat(RPixelFormat format) return RPixelStrings[format]; } -matrix_float4x4 make_matrix_float4x4(const float *v) +static matrix_float4x4 make_matrix_float4x4(const float *v) { simd_float4 P = simd_make_float4(v[0], v[1], v[2], v[3]); v += 4; @@ -76,36 +76,7 @@ matrix_float4x4 make_matrix_float4x4(const float *v) return mat; } -matrix_float4x4 matrix_proj_ortho(float left, float right, float top, float bottom) -{ -#if 0 - float near = 0; - float far = 1; - float sx = 2 / (right - left); - float sy = 2 / (top - bottom); - float sz = 1 / (far - near); - float tx = (right + left) / (left - right); - float ty = (top + bottom) / (bottom - top); - float tz = near / (far - near); - simd_float4 P = simd_make_float4(sx, 0, 0, 0); - simd_float4 Q = simd_make_float4(0, sy, 0, 0); - simd_float4 R = simd_make_float4(0, 0, sz, 0); - simd_float4 S = simd_make_float4(tx, ty, tz, 1); -#else - float sx = 2 / (right - left); - float sy = 2 / (top - bottom); - float tx = (right + left) / (left - right); - float ty = (top + bottom) / (bottom - top); - simd_float4 P = simd_make_float4(sx, 0, 0, 0); - simd_float4 Q = simd_make_float4(0, sy, 0, 0); - simd_float4 R = simd_make_float4(0, 0, 1, 0); - simd_float4 S = simd_make_float4(tx, ty, 0, 1); -#endif - matrix_float4x4 mat = {P, Q, R, S}; - return mat; -} - -matrix_float4x4 matrix_rotate_z(float rot) +static matrix_float4x4 matrix_rotate_z(float rot) { float cz, sz; __sincosf(rot, &sz, &cz); @@ -119,6 +90,20 @@ matrix_float4x4 matrix_rotate_z(float rot) return mat; } +matrix_float4x4 matrix_proj_ortho(float left, float right, float top, float bottom) +{ + float sx = 2 / (right - left); + float sy = 2 / (top - bottom); + float tx = (right + left) / (left - right); + float ty = (top + bottom) / (bottom - top); + simd_float4 P = simd_make_float4(sx, 0, 0, 0); + simd_float4 Q = simd_make_float4(0, sy, 0, 0); + simd_float4 R = simd_make_float4(0, 0, 1, 0); + simd_float4 S = simd_make_float4(tx, ty, 0, 1); + matrix_float4x4 mat = {P, Q, R, S}; + return mat; +} + /* * CONTEXT */ @@ -257,17 +242,11 @@ matrix_float4x4 matrix_rotate_z(float rot) - (void)setRotation:(unsigned)rotation { - _rotation = 270 * rotation; + matrix_float4x4 rot; + _rotation = 270 * rotation; /* Calculate projection. */ - _mvp_no_rot = matrix_proj_ortho(0, 1, 0, 1); - bool allow_rotate = true; - if (!allow_rotate) - { - _mvp = _mvp_no_rot; - return; - } - - matrix_float4x4 rot = matrix_rotate_z((float)(M_PI * _rotation / 180.0f)); + _mvp_no_rot = matrix_proj_ortho(0, 1, 0, 1); + rot = matrix_rotate_z((float)(M_PI * _rotation / 180.0f)); _mvp = simd_mul(rot, _mvp_no_rot); _uniforms.projectionMatrix = _mvp; _uniformsNoRotate.projectionMatrix = _mvp_no_rot; @@ -331,7 +310,7 @@ matrix_float4x4 matrix_rotate_z(float rot) NSError *err; MTLVertexDescriptor *vd = [self _spriteVertexDescriptor]; MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new]; - psd.label = @"clear_state"; + psd.label = @"clear_state"; MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0]; ca.pixelFormat = _layer.pixelFormat; diff --git a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj index f1b054d07e..e24e3248e2 100644 --- a/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj +++ b/pkg/apple/RetroArch_Metal.xcodeproj/project.pbxproj @@ -357,7 +357,6 @@ 05A8C64C20DB72F000FF7857 /* snowflake_sm4.hlsl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = snowflake_sm4.hlsl.h; sourceTree = ""; }; 05A8C64D20DB72F000FF7857 /* mipmapgen_sm5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mipmapgen_sm5.h; sourceTree = ""; }; 05A8C64E20DB72F000FF7857 /* font.hlsl.d3d9.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = font.hlsl.d3d9.h; sourceTree = ""; }; - 05A8C67420DB72F000FF7857 /* video_state_tracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_state_tracker.h; sourceTree = ""; }; 05A8C67520DB72F000FF7857 /* video_thread_wrapper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_thread_wrapper.c; sourceTree = ""; }; 05A8C67620DB72F000FF7857 /* video_driver.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_driver.c; sourceTree = ""; }; 05A8C67720DB72F000FF7857 /* video_crt_switch.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_crt_switch.c; sourceTree = ""; }; @@ -379,7 +378,6 @@ 05A8C77020DB72F100FF7857 /* d3d_common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = d3d_common.h; sourceTree = ""; }; 05A8C77720DB72F100FF7857 /* d3d10_common.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = d3d10_common.c; sourceTree = ""; }; 05A8C77A20DB72F100FF7857 /* video_display_server.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_display_server.h; sourceTree = ""; }; - 05A8C77B20DB72F100FF7857 /* video_state_tracker.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_state_tracker.c; sourceTree = ""; }; 05A8C77D20DB72F100FF7857 /* vga_font.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = vga_font.c; sourceTree = ""; }; 05A8C78120DB72F100FF7857 /* d3d10_font.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = d3d10_font.c; sourceTree = ""; }; 05A8C78320DB72F100FF7857 /* metal_raster_font.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = metal_raster_font.m; sourceTree = ""; }; @@ -430,7 +428,6 @@ 05BF821C20ED69D100D95B19 /* config.def.keybinds.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = config.def.keybinds.h; path = ../../config.def.keybinds.h; sourceTree = ""; }; 05BF821D20ED69D100D95B19 /* configuration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = configuration.h; path = ../../configuration.h; sourceTree = ""; }; 05C5D53320E3DD0900654EE4 /* input_types.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_types.h; sourceTree = ""; }; - 05C5D53420E3DD0900654EE4 /* input_remote.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_remote.c; sourceTree = ""; }; 05C5D53820E3DD0900654EE4 /* cocoa_input.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cocoa_input.h; sourceTree = ""; }; 05C5D54120E3DD0900654EE4 /* sdl_input.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = sdl_input.c; sourceTree = ""; }; 05C5D54220E3DD0900654EE4 /* cocoa_input.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = cocoa_input.c; sourceTree = ""; }; @@ -453,7 +450,6 @@ 05C5D56320E3DD0900654EE4 /* keyboard_event_apple.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = keyboard_event_apple.c; sourceTree = ""; }; 05C5D56620E3DD0900654EE4 /* keyboard_event_apple.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = keyboard_event_apple.h; sourceTree = ""; }; 05C5D56A20E3DD0900654EE4 /* input_remapping.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_remapping.h; sourceTree = ""; }; - 05C5D56B20E3DD0900654EE4 /* input_mapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_mapper.h; sourceTree = ""; }; 05C5D56C20E3DD0900654EE4 /* input_overlay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_overlay.h; sourceTree = ""; }; 05C5D56D20E3DD0900654EE4 /* input_defines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_defines.h; sourceTree = ""; }; 05C5D56F20E3DD0900654EE4 /* btstack_hid.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = btstack_hid.c; sourceTree = ""; }; @@ -474,10 +470,6 @@ 05C5D58720E3DD0900654EE4 /* sdl_joypad.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = sdl_joypad.c; sourceTree = ""; }; 05C5D58D20E3DD0900654EE4 /* mfi_joypad.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = mfi_joypad.m; sourceTree = ""; }; 05C5D59820E3DD0A00654EE4 /* hid_joypad.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = hid_joypad.c; sourceTree = ""; }; - 05C5D59F20E3DD0A00654EE4 /* input_remote.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_remote.h; sourceTree = ""; }; - 05C5D5A020E3DD0A00654EE4 /* input_overlay.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_overlay.c; sourceTree = ""; }; - 05C5D5A120E3DD0A00654EE4 /* input_mapper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_mapper.c; sourceTree = ""; }; - 05C5D5A220E3DD0A00654EE4 /* input_remapping.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_remapping.c; sourceTree = ""; }; 05C5D5A320E3DD0A00654EE4 /* input_driver.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_driver.c; sourceTree = ""; }; 05D7753120A55D2700646447 /* BaseConfig.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = BaseConfig.xcconfig; sourceTree = ""; }; 05D7753320A5678300646447 /* griffin_cpp.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = griffin_cpp.cpp; path = ../../griffin/griffin_cpp.cpp; sourceTree = ""; }; @@ -960,8 +952,6 @@ 05A8C71320DB72F000FF7857 /* video_filter.h */, 05A8C79E20DB72F100FF7857 /* video_shader_parse.c */, 05A8C70E20DB72F000FF7857 /* video_shader_parse.h */, - 05A8C77B20DB72F100FF7857 /* video_state_tracker.c */, - 05A8C67420DB72F000FF7857 /* video_state_tracker.h */, 05A8C67520DB72F000FF7857 /* video_thread_wrapper.c */, 05A8C7A020DB72F100FF7857 /* video_thread_wrapper.h */, ); @@ -1201,14 +1191,8 @@ 05C5D56120E3DD0900654EE4 /* input_driver.h */, 05C5D58320E3DD0900654EE4 /* input_keymaps.c */, 05C5D54C20E3DD0900654EE4 /* input_keymaps.h */, - 05C5D5A120E3DD0A00654EE4 /* input_mapper.c */, - 05C5D56B20E3DD0900654EE4 /* input_mapper.h */, - 05C5D5A020E3DD0A00654EE4 /* input_overlay.c */, 05C5D56C20E3DD0900654EE4 /* input_overlay.h */, - 05C5D5A220E3DD0A00654EE4 /* input_remapping.c */, 05C5D56A20E3DD0900654EE4 /* input_remapping.h */, - 05C5D53420E3DD0900654EE4 /* input_remote.c */, - 05C5D59F20E3DD0A00654EE4 /* input_remote.h */, 05C5D53320E3DD0900654EE4 /* input_types.h */, ); name = input;