(Metal) Cleanups

This commit is contained in:
reallibretroadmin 2023-01-08 05:48:06 +01:00
parent 29f165026a
commit 074f19ca90
3 changed files with 24 additions and 65 deletions

View File

@ -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

View File

@ -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;

View File

@ -357,7 +357,6 @@
05A8C64C20DB72F000FF7857 /* snowflake_sm4.hlsl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = snowflake_sm4.hlsl.h; sourceTree = "<group>"; };
05A8C64D20DB72F000FF7857 /* mipmapgen_sm5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mipmapgen_sm5.h; sourceTree = "<group>"; };
05A8C64E20DB72F000FF7857 /* font.hlsl.d3d9.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = font.hlsl.d3d9.h; sourceTree = "<group>"; };
05A8C67420DB72F000FF7857 /* video_state_tracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_state_tracker.h; sourceTree = "<group>"; };
05A8C67520DB72F000FF7857 /* video_thread_wrapper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_thread_wrapper.c; sourceTree = "<group>"; };
05A8C67620DB72F000FF7857 /* video_driver.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_driver.c; sourceTree = "<group>"; };
05A8C67720DB72F000FF7857 /* video_crt_switch.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_crt_switch.c; sourceTree = "<group>"; };
@ -379,7 +378,6 @@
05A8C77020DB72F100FF7857 /* d3d_common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = d3d_common.h; sourceTree = "<group>"; };
05A8C77720DB72F100FF7857 /* d3d10_common.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = d3d10_common.c; sourceTree = "<group>"; };
05A8C77A20DB72F100FF7857 /* video_display_server.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_display_server.h; sourceTree = "<group>"; };
05A8C77B20DB72F100FF7857 /* video_state_tracker.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_state_tracker.c; sourceTree = "<group>"; };
05A8C77D20DB72F100FF7857 /* vga_font.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = vga_font.c; sourceTree = "<group>"; };
05A8C78120DB72F100FF7857 /* d3d10_font.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = d3d10_font.c; sourceTree = "<group>"; };
05A8C78320DB72F100FF7857 /* metal_raster_font.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = metal_raster_font.m; sourceTree = "<group>"; };
@ -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 = "<group>"; };
05BF821D20ED69D100D95B19 /* configuration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = configuration.h; path = ../../configuration.h; sourceTree = "<group>"; };
05C5D53320E3DD0900654EE4 /* input_types.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_types.h; sourceTree = "<group>"; };
05C5D53420E3DD0900654EE4 /* input_remote.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_remote.c; sourceTree = "<group>"; };
05C5D53820E3DD0900654EE4 /* cocoa_input.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cocoa_input.h; sourceTree = "<group>"; };
05C5D54120E3DD0900654EE4 /* sdl_input.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = sdl_input.c; sourceTree = "<group>"; };
05C5D54220E3DD0900654EE4 /* cocoa_input.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = cocoa_input.c; sourceTree = "<group>"; };
@ -453,7 +450,6 @@
05C5D56320E3DD0900654EE4 /* keyboard_event_apple.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = keyboard_event_apple.c; sourceTree = "<group>"; };
05C5D56620E3DD0900654EE4 /* keyboard_event_apple.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = keyboard_event_apple.h; sourceTree = "<group>"; };
05C5D56A20E3DD0900654EE4 /* input_remapping.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_remapping.h; sourceTree = "<group>"; };
05C5D56B20E3DD0900654EE4 /* input_mapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_mapper.h; sourceTree = "<group>"; };
05C5D56C20E3DD0900654EE4 /* input_overlay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_overlay.h; sourceTree = "<group>"; };
05C5D56D20E3DD0900654EE4 /* input_defines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_defines.h; sourceTree = "<group>"; };
05C5D56F20E3DD0900654EE4 /* btstack_hid.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = btstack_hid.c; sourceTree = "<group>"; };
@ -474,10 +470,6 @@
05C5D58720E3DD0900654EE4 /* sdl_joypad.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = sdl_joypad.c; sourceTree = "<group>"; };
05C5D58D20E3DD0900654EE4 /* mfi_joypad.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = mfi_joypad.m; sourceTree = "<group>"; };
05C5D59820E3DD0A00654EE4 /* hid_joypad.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = hid_joypad.c; sourceTree = "<group>"; };
05C5D59F20E3DD0A00654EE4 /* input_remote.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = input_remote.h; sourceTree = "<group>"; };
05C5D5A020E3DD0A00654EE4 /* input_overlay.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_overlay.c; sourceTree = "<group>"; };
05C5D5A120E3DD0A00654EE4 /* input_mapper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_mapper.c; sourceTree = "<group>"; };
05C5D5A220E3DD0A00654EE4 /* input_remapping.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_remapping.c; sourceTree = "<group>"; };
05C5D5A320E3DD0A00654EE4 /* input_driver.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = input_driver.c; sourceTree = "<group>"; };
05D7753120A55D2700646447 /* BaseConfig.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = BaseConfig.xcconfig; sourceTree = "<group>"; };
05D7753320A5678300646447 /* griffin_cpp.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = griffin_cpp.cpp; path = ../../griffin/griffin_cpp.cpp; sourceTree = "<group>"; };
@ -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;