mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 06:44:27 +00:00
(Metal) Small cleanups
This commit is contained in:
parent
2b0c86f1f5
commit
29f165026a
@ -24,7 +24,6 @@
|
||||
#include "metal_shader_types.h"
|
||||
|
||||
#include "../../gfx_display.h"
|
||||
#include "../../../retroarch.h"
|
||||
|
||||
/* TODO/FIXME: implement triple buffering */
|
||||
/*! @brief maximum inflight frames */
|
||||
|
@ -37,21 +37,11 @@ static NSString *RPixelStrings[RPixelFormatCount];
|
||||
|
||||
NSUInteger RPixelFormatToBPP(RPixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case RPixelFormatBGRA8Unorm:
|
||||
case RPixelFormatBGRX8Unorm:
|
||||
return 4;
|
||||
|
||||
case RPixelFormatB5G6R5Unorm:
|
||||
case RPixelFormatBGRA4Unorm:
|
||||
if ( format == RPixelFormatB5G6R5Unorm
|
||||
|| format == RPixelFormatBGRA4Unorm )
|
||||
return 2;
|
||||
|
||||
default:
|
||||
RARCH_ERR("[Metal]: unknown RPixel format: %d\n", format);
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
static NSString *NSStringFromRPixelFormat(RPixelFormat format)
|
||||
{
|
||||
@ -69,10 +59,7 @@ static NSString *NSStringFromRPixelFormat(RPixelFormat format)
|
||||
});
|
||||
|
||||
if (format >= RPixelFormatCount)
|
||||
{
|
||||
format = RPixelFormatInvalid;
|
||||
}
|
||||
|
||||
return RPixelStrings[format];
|
||||
}
|
||||
|
||||
@ -85,28 +72,35 @@ matrix_float4x4 make_matrix_float4x4(const float *v)
|
||||
simd_float4 R = simd_make_float4(v[0], v[1], v[2], v[3]);
|
||||
v += 4;
|
||||
simd_float4 S = simd_make_float4(v[0], v[1], v[2], v[3]);
|
||||
|
||||
matrix_float4x4 mat = {P, Q, R, S};
|
||||
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;
|
||||
}
|
||||
@ -190,6 +184,8 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
int i;
|
||||
|
||||
_inflightSemaphore = dispatch_semaphore_create(MAX_INFLIGHT);
|
||||
_device = d;
|
||||
_layer = layer;
|
||||
@ -237,11 +233,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
if (![self _initMenuStates])
|
||||
return nil;
|
||||
|
||||
for (int i = 0; i < CHAIN_LENGTH; i++)
|
||||
{
|
||||
for (i = 0; i < CHAIN_LENGTH; i++)
|
||||
_chain[i] = [[BufferChain alloc] initWithDevice:_device blockLen:65536];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -264,10 +258,8 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
- (void)setRotation:(unsigned)rotation
|
||||
{
|
||||
_rotation = 270 * rotation;
|
||||
|
||||
/* Calculate projection. */
|
||||
_mvp_no_rot = matrix_proj_ortho(0, 1, 0, 1);
|
||||
|
||||
bool allow_rotate = true;
|
||||
if (!allow_rotate)
|
||||
{
|
||||
@ -277,7 +269,6 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
|
||||
matrix_float4x4 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;
|
||||
}
|
||||
@ -337,6 +328,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
|
||||
- (bool)_initClearState
|
||||
{
|
||||
NSError *err;
|
||||
MTLVertexDescriptor *vd = [self _spriteVertexDescriptor];
|
||||
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
|
||||
psd.label = @"clear_state";
|
||||
@ -348,7 +340,6 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
psd.vertexFunction = [_library newFunctionWithName:@"stock_vertex"];
|
||||
psd.fragmentFunction = [_library newFunctionWithName:@"stock_fragment_color"];
|
||||
|
||||
NSError *err;
|
||||
_clearState = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
|
||||
if (err != nil)
|
||||
{
|
||||
@ -361,6 +352,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
|
||||
- (bool)_initMenuStates
|
||||
{
|
||||
NSError *err;
|
||||
MTLVertexDescriptor *vd = [self _spriteVertexDescriptor];
|
||||
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
|
||||
psd.label = @"stock";
|
||||
@ -378,7 +370,6 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
psd.vertexFunction = [_library newFunctionWithName:@"stock_vertex"];
|
||||
psd.fragmentFunction = [_library newFunctionWithName:@"stock_fragment"];
|
||||
|
||||
NSError *err;
|
||||
_states[VIDEO_SHADER_STOCK_BLEND][0] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
|
||||
if (err != nil)
|
||||
{
|
||||
@ -563,11 +554,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
}
|
||||
|
||||
BOOL mipmapped = filter == TEXTURE_FILTER_MIPMAP_LINEAR || filter == TEXTURE_FILTER_MIPMAP_NEAREST;
|
||||
|
||||
Texture *tex = [Texture new];
|
||||
tex.texture = [self newTexture:image mipmapped:mipmapped];
|
||||
tex.sampler = _samplers[filter];
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
@ -598,9 +587,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
- (id<CAMetalDrawable>)nextDrawable
|
||||
{
|
||||
if (_drawable == nil)
|
||||
{
|
||||
_drawable = _layer.nextDrawable;
|
||||
}
|
||||
return _drawable;
|
||||
}
|
||||
|
||||
@ -615,7 +602,8 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
|
||||
- (id<MTLCommandBuffer>)blitCommandBuffer
|
||||
{
|
||||
if (!_blitCommandBuffer) {
|
||||
if (!_blitCommandBuffer)
|
||||
{
|
||||
_blitCommandBuffer = [_commandQueue commandBuffer];
|
||||
_blitCommandBuffer.label = @"Blit command buffer";
|
||||
}
|
||||
@ -702,9 +690,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
rpd.colorAttachments[0].loadAction = MTLLoadActionClear;
|
||||
rpd.colorAttachments[0].texture = self.nextDrawable.texture;
|
||||
if (_captureEnabled)
|
||||
{
|
||||
_backBuffer = self.nextDrawable.texture;
|
||||
}
|
||||
_rce = [_commandBuffer renderCommandEncoderWithDescriptor:rpd];
|
||||
_rce.label = @"Frame command encoder";
|
||||
}
|
||||
@ -818,9 +804,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
|
||||
- (instancetype)initWithBuffer:(id<MTLBuffer>)src
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
_src = src;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -880,8 +864,7 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
|
||||
- (bool)allocRange:(BufferRange *)range length:(NSUInteger)length
|
||||
{
|
||||
MTLResourceOptions opts;
|
||||
opts = PLATFORM_METAL_RESOURCE_STORAGE_MODE;
|
||||
MTLResourceOptions opts = PLATFORM_METAL_RESOURCE_STORAGE_MODE;
|
||||
memset(range, 0, sizeof(*range));
|
||||
|
||||
if (!_head)
|
||||
@ -959,9 +942,7 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
id<MTLFunction> function = [library newFunctionWithName:name];
|
||||
id<MTLComputePipelineState> kernel = [device newComputePipelineStateWithFunction:function error:error];
|
||||
if (*error != nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new];
|
||||
sd.minFilter = MTLSamplerMinMagFilterNearest;
|
||||
@ -1001,7 +982,6 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
1);
|
||||
|
||||
[ce dispatchThreadgroups:count threadsPerThreadgroup:size];
|
||||
|
||||
[ce endEncoding];
|
||||
}
|
||||
|
||||
@ -1021,7 +1001,6 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
MTLSize count = MTLSizeMake((tin.length + 00) / 32, 1, 1);
|
||||
|
||||
[ce dispatchThreadgroups:count threadsPerThreadgroup:size];
|
||||
|
||||
[ce endEncoding];
|
||||
}
|
||||
|
||||
@ -1108,29 +1087,18 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
|
||||
- (MTLPrimitiveType)_toPrimitiveType:(enum gfx_display_prim_type)prim
|
||||
{
|
||||
switch (prim)
|
||||
{
|
||||
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
|
||||
if (prim == GFX_DISPLAY_PRIM_TRIANGLESTRIP)
|
||||
return MTLPrimitiveTypeTriangleStrip;
|
||||
case GFX_DISPLAY_PRIM_TRIANGLES:
|
||||
default:
|
||||
/* Unexpected primitive type, defaulting to triangle */
|
||||
break;
|
||||
}
|
||||
|
||||
return MTLPrimitiveTypeTriangle;
|
||||
}
|
||||
|
||||
- (void)drawPipeline:(gfx_display_ctx_draw_t *)draw
|
||||
{
|
||||
static struct video_coords blank_coords;
|
||||
|
||||
draw->x = 0;
|
||||
draw->y = 0;
|
||||
draw->matrix_data = NULL;
|
||||
|
||||
_uniforms.outputSize = simd_make_float2(_context.viewport->full_width, _context.viewport->full_height);
|
||||
|
||||
draw->backend_data = &_uniforms;
|
||||
draw->backend_data_size = sizeof(_uniforms);
|
||||
|
||||
@ -1264,9 +1232,7 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
_format = RPixelFormatBGRA8Unorm;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -1278,8 +1244,7 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
NSString *sizeDesc = NSStringFromSize(_size);
|
||||
#endif
|
||||
return [NSString stringWithFormat:@"( format = %@, frame = %@ )",
|
||||
NSStringFromRPixelFormat(_format),
|
||||
sizeDesc];
|
||||
NSStringFromRPixelFormat(_format), sizeDesc];
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1292,7 +1257,6 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
CGSize _size; /* Size of view in pixels */
|
||||
CGRect _frame;
|
||||
NSUInteger _bpp;
|
||||
|
||||
id<MTLTexture> _src; /* Source texture */
|
||||
bool _srcDirty;
|
||||
}
|
||||
@ -1308,13 +1272,9 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
_context = c;
|
||||
_visible = YES;
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
_drawState = ViewDrawStateEncoder;
|
||||
}
|
||||
else
|
||||
{
|
||||
_drawState = ViewDrawStateAll;
|
||||
}
|
||||
self.size = d.size;
|
||||
self.frame = CGRectMake(0, 0, 1, 1);
|
||||
}
|
||||
@ -1324,9 +1284,7 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
- (void)setSize:(CGSize)size
|
||||
{
|
||||
if (CGSizeEqualToSize(_size, size))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_size = size;
|
||||
|
||||
@ -1339,7 +1297,8 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
_texture = [_context.device newTextureWithDescriptor:td];
|
||||
}
|
||||
|
||||
if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm)
|
||||
if ( _format != RPixelFormatBGRA8Unorm
|
||||
&& _format != RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint
|
||||
width:(NSUInteger)size.width
|
||||
@ -1357,9 +1316,7 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
if (CGRectEqualToRect(_frame, frame))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_frame = frame;
|
||||
|
||||
@ -1384,7 +1341,8 @@ static const NSUInteger kConstantAlignment = 4;
|
||||
|
||||
- (void)_convertFormat
|
||||
{
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm)
|
||||
if ( _format == RPixelFormatBGRA8Unorm
|
||||
|| _format == RPixelFormatBGRX8Unorm)
|
||||
return;
|
||||
|
||||
if (!_srcDirty)
|
||||
|
@ -375,7 +375,6 @@
|
||||
05A8C75E20DB72F100FF7857 /* d3d_common.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = d3d_common.c; sourceTree = "<group>"; };
|
||||
05A8C76320DB72F100FF7857 /* d3d10_common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = d3d10_common.h; sourceTree = "<group>"; };
|
||||
05A8C76820DB72F100FF7857 /* vulkan_common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = vulkan_common.h; sourceTree = "<group>"; };
|
||||
05A8C76920DB72F100FF7857 /* metal_common.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = metal_common.m; sourceTree = "<group>"; };
|
||||
05A8C76F20DB72F100FF7857 /* gl_common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = gl_common.h; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
@ -402,11 +401,6 @@
|
||||
05A8C79E20DB72F100FF7857 /* video_shader_parse.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_shader_parse.c; sourceTree = "<group>"; };
|
||||
05A8C79F20DB72F100FF7857 /* video_driver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_driver.h; sourceTree = "<group>"; };
|
||||
05A8C7A020DB72F100FF7857 /* video_thread_wrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_thread_wrapper.h; sourceTree = "<group>"; };
|
||||
05A8C7A220DB72F100FF7857 /* d3d9_renderchain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = d3d9_renderchain.h; sourceTree = "<group>"; };
|
||||
05A8C7A320DB72F100FF7857 /* gl2_renderchain.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = gl2_renderchain.c; sourceTree = "<group>"; };
|
||||
05A8C7A420DB72F100FF7857 /* d3d9_cg_renderchain.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = d3d9_cg_renderchain.c; sourceTree = "<group>"; };
|
||||
05A8C7A520DB72F100FF7857 /* d3d9_hlsl_renderchain.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = d3d9_hlsl_renderchain.c; sourceTree = "<group>"; };
|
||||
05A8C7A620DB72F100FF7857 /* gl1_renderchain.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = gl1_renderchain.c; sourceTree = "<group>"; };
|
||||
05A8C7A720DB72F100FF7857 /* font_driver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = font_driver.h; sourceTree = "<group>"; };
|
||||
05A8C7A820DB72F100FF7857 /* video_defines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = video_defines.h; sourceTree = "<group>"; };
|
||||
05A8C7A920DB72F100FF7857 /* video_coord_array.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = video_coord_array.c; sourceTree = "<group>"; };
|
||||
@ -950,7 +944,6 @@
|
||||
05A8C5D620DB72F000FF7857 /* drivers_context */,
|
||||
05A8C77C20DB72F100FF7857 /* drivers_font */,
|
||||
05A8C7AA20DB72F100FF7857 /* drivers_font_renderer */,
|
||||
05A8C7A120DB72F100FF7857 /* drivers_renderchain */,
|
||||
05A8C78E20DB72F100FF7857 /* drivers_shader */,
|
||||
05A8C73920DB72F100FF7857 /* font_driver.c */,
|
||||
05A8C7A720DB72F100FF7857 /* font_driver.h */,
|
||||
@ -1100,7 +1093,6 @@
|
||||
05A8C75D20DB72F100FF7857 /* gl_common.c */,
|
||||
05A8C76F20DB72F100FF7857 /* gl_common.h */,
|
||||
05A8C74420DB72F100FF7857 /* metal_common.h */,
|
||||
05A8C76920DB72F100FF7857 /* metal_common.m */,
|
||||
05A8C73C20DB72F100FF7857 /* vulkan_common.c */,
|
||||
05A8C76820DB72F100FF7857 /* vulkan_common.h */,
|
||||
);
|
||||
@ -1149,18 +1141,6 @@
|
||||
path = drivers_shader;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
05A8C7A120DB72F100FF7857 /* drivers_renderchain */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
05A8C7A220DB72F100FF7857 /* d3d9_renderchain.h */,
|
||||
05A8C7A320DB72F100FF7857 /* gl2_renderchain.c */,
|
||||
05A8C7A420DB72F100FF7857 /* d3d9_cg_renderchain.c */,
|
||||
05A8C7A520DB72F100FF7857 /* d3d9_hlsl_renderchain.c */,
|
||||
05A8C7A620DB72F100FF7857 /* gl1_renderchain.c */,
|
||||
);
|
||||
path = drivers_renderchain;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
05A8C7AA20DB72F100FF7857 /* drivers_font_renderer */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user