mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 18:40:09 +00:00
formatting
This commit is contained in:
parent
a0900ec433
commit
44ca1062b0
@ -10,7 +10,7 @@
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
@protocol FilterDelegate
|
||||
-(void)configure:(id<MTLCommandEncoder>)encoder;
|
||||
- (void)configure:(id<MTLCommandEncoder>)encoder;
|
||||
@end
|
||||
|
||||
@interface Filter : NSObject
|
||||
@ -18,9 +18,9 @@
|
||||
@property (nonatomic, readwrite) id<FilterDelegate> delegate;
|
||||
@property (nonatomic, readonly) id<MTLSamplerState> sampler;
|
||||
|
||||
-(void)apply:(id<MTLCommandBuffer>)cb in:(id<MTLTexture>)tin out:(id<MTLTexture>)tout;
|
||||
-(void)apply:(id<MTLCommandBuffer>)cb inBuf:(id<MTLBuffer>)tin outTex:(id<MTLTexture>)tout;
|
||||
- (void)apply:(id<MTLCommandBuffer>)cb in:(id<MTLTexture>)tin out:(id<MTLTexture>)tout;
|
||||
- (void)apply:(id<MTLCommandBuffer>)cb inBuf:(id<MTLBuffer>)tin outTex:(id<MTLTexture>)tout;
|
||||
|
||||
+(instancetype)newFilterWithFunctionName:(NSString *)name device:(id<MTLDevice>)device library:(id<MTLLibrary>)library error:(NSError **)error;
|
||||
+ (instancetype)newFilterWithFunctionName:(NSString *)name device:(id<MTLDevice>)device library:(id<MTLLibrary>)library error:(NSError **)error;
|
||||
|
||||
@end
|
||||
|
@ -10,21 +10,24 @@
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
@interface Filter()
|
||||
-( instancetype)initWithKernel:(id<MTLComputePipelineState>)kernel sampler:(id<MTLSamplerState>)sampler;
|
||||
- (instancetype)initWithKernel:(id<MTLComputePipelineState>)kernel sampler:(id<MTLSamplerState>)sampler;
|
||||
@end
|
||||
|
||||
@implementation Filter {
|
||||
@implementation Filter
|
||||
{
|
||||
id<MTLComputePipelineState> _kernel;
|
||||
}
|
||||
|
||||
+(instancetype)newFilterWithFunctionName:(NSString *)name device:(id<MTLDevice>)device library:(id<MTLLibrary>)library error:(NSError **)error {
|
||||
+ (instancetype)newFilterWithFunctionName:(NSString *)name device:(id<MTLDevice>)device library:(id<MTLLibrary>)library error:(NSError **)error
|
||||
{
|
||||
id<MTLFunction> function = [library newFunctionWithName:name];
|
||||
id<MTLComputePipelineState> kernel = [device newComputePipelineStateWithFunction:function error:error];
|
||||
if (*error != nil) {
|
||||
if (*error != nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
MTLSamplerDescriptor * sd = [MTLSamplerDescriptor new];
|
||||
MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new];
|
||||
sd.minFilter = MTLSamplerMinMagFilterNearest;
|
||||
sd.magFilter = MTLSamplerMinMagFilterNearest;
|
||||
sd.sAddressMode = MTLSamplerAddressModeClampToEdge;
|
||||
@ -35,15 +38,18 @@
|
||||
return [[Filter alloc] initWithKernel:kernel sampler:sampler];
|
||||
}
|
||||
|
||||
-( instancetype)initWithKernel:(id<MTLComputePipelineState>)kernel sampler:(id<MTLSamplerState>)sampler {
|
||||
if (self = [super init]) {
|
||||
- (instancetype)initWithKernel:(id<MTLComputePipelineState>)kernel sampler:(id<MTLSamplerState>)sampler
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
_kernel = kernel;
|
||||
_sampler = sampler;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)apply:(id<MTLCommandBuffer>)cb in:(id<MTLTexture>)tin out:(id<MTLTexture>)tout {
|
||||
- (void)apply:(id<MTLCommandBuffer>)cb in:(id<MTLTexture>)tin out:(id<MTLTexture>)tout
|
||||
{
|
||||
id<MTLComputeCommandEncoder> ce = [cb computeCommandEncoder];
|
||||
ce.label = @"filter kernel";
|
||||
[ce pushDebugGroup:@"filter kernel"];
|
||||
@ -56,7 +62,8 @@
|
||||
[self.delegate configure:ce];
|
||||
|
||||
MTLSize size = MTLSizeMake(16, 16, 1);
|
||||
MTLSize count = MTLSizeMake((tin.width + size.width + 1) / size.width, (tin.height + size.height + 1) / size.height, 1);
|
||||
MTLSize count = MTLSizeMake((tin.width + size.width + 1) / size.width, (tin.height + size.height + 1) / size.height,
|
||||
1);
|
||||
|
||||
[ce dispatchThreadgroups:count threadsPerThreadgroup:size];
|
||||
|
||||
@ -64,7 +71,8 @@
|
||||
[ce endEncoding];
|
||||
}
|
||||
|
||||
-(void)apply:(id<MTLCommandBuffer>)cb inBuf:(id<MTLBuffer>)tin outTex:(id<MTLTexture>)tout {
|
||||
- (void)apply:(id<MTLCommandBuffer>)cb inBuf:(id<MTLBuffer>)tin outTex:(id<MTLTexture>)tout
|
||||
{
|
||||
id<MTLComputeCommandEncoder> ce = [cb computeCommandEncoder];
|
||||
ce.label = @"filter kernel";
|
||||
[ce pushDebugGroup:@"filter kernel"];
|
||||
|
@ -27,7 +27,8 @@
|
||||
|
||||
#pragma mark - Pixel Formats
|
||||
|
||||
typedef NS_ENUM(NSUInteger, RPixelFormat) {
|
||||
typedef NS_ENUM(NSUInteger, RPixelFormat)
|
||||
{
|
||||
|
||||
RPixelFormatInvalid,
|
||||
|
||||
@ -44,7 +45,8 @@ typedef NS_ENUM(NSUInteger, RPixelFormat) {
|
||||
extern NSUInteger RPixelFormatToBPP(RPixelFormat format);
|
||||
extern NSString *NSStringFromRPixelFormat(RPixelFormat format);
|
||||
|
||||
typedef NS_ENUM(NSUInteger, RTextureFilter) {
|
||||
typedef NS_ENUM(NSUInteger, RTextureFilter)
|
||||
{
|
||||
RTextureFilterNearest,
|
||||
RTextureFilterLinear,
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
NSUInteger RPixelFormatToBPP(RPixelFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
switch (format)
|
||||
{
|
||||
case RPixelFormatBGRA8Unorm:
|
||||
case RPixelFormatBGRX8Unorm:
|
||||
return 4;
|
||||
@ -43,7 +44,8 @@ NSString *NSStringFromRPixelFormat(RPixelFormat format)
|
||||
|
||||
});
|
||||
|
||||
if (format >= RPixelFormatCount) {
|
||||
if (format >= RPixelFormatCount)
|
||||
{
|
||||
format = RPixelFormatInvalid;
|
||||
}
|
||||
|
||||
|
@ -25,15 +25,19 @@
|
||||
- (instancetype)initWithDescriptor:(ViewDescriptor *)d context:(Context *)c
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
if (self)
|
||||
{
|
||||
_format = d.format;
|
||||
_bpp = RPixelFormatToBPP(_format);
|
||||
_filter = d.filter;
|
||||
_context = c;
|
||||
_visible = YES;
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm) {
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
_drawState = ViewDrawStateEncoder;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
_drawState = ViewDrawStateAll;
|
||||
}
|
||||
self.size = d.size;
|
||||
@ -44,7 +48,8 @@
|
||||
|
||||
- (void)setSize:(CGSize)size
|
||||
{
|
||||
if (CGSizeEqualToSize(_size, size)) {
|
||||
if (CGSizeEqualToSize(_size, size))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -60,7 +65,8 @@
|
||||
_texture = [_context.device newTextureWithDescriptor:td];
|
||||
}
|
||||
|
||||
if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm) {
|
||||
if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
_pixels = [_context.device newBufferWithLength:(NSUInteger)(size.width * size.height * 2)
|
||||
options:MTLResourceStorageModeManaged];
|
||||
}
|
||||
@ -73,7 +79,8 @@
|
||||
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
if (CGRectEqualToRect(_frame, frame)) {
|
||||
if (CGRectEqualToRect(_frame, frame))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,7 +121,8 @@
|
||||
_pixelsDirty = NO;
|
||||
}
|
||||
|
||||
- (void)drawWithContext:(Context *)ctx {
|
||||
- (void)drawWithContext:(Context *)ctx
|
||||
{
|
||||
[self _convertFormat];
|
||||
}
|
||||
|
||||
@ -127,24 +135,29 @@
|
||||
|
||||
- (void)updateFrame:(void const *)src pitch:(NSUInteger)pitch
|
||||
{
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm) {
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
[_texture replaceRegion:MTLRegionMake2D(0, 0, (NSUInteger)_size.width, (NSUInteger)_size.height)
|
||||
mipmapLevel:0 withBytes:src
|
||||
bytesPerRow:(NSUInteger)(4 * pitch)];
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
void *dst = _pixels.contents;
|
||||
size_t len = (size_t)(_bpp * _size.width);
|
||||
assert(len <= pitch); // the length can't be larger?
|
||||
|
||||
if (len < pitch) {
|
||||
for (int i = 0; i < _size.height; i++) {
|
||||
if (len < pitch)
|
||||
{
|
||||
for (int i = 0; i < _size.height; i++)
|
||||
{
|
||||
memcpy(dst, src, len);
|
||||
dst += len;
|
||||
src += pitch;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
memcpy(dst, src, _pixels.length);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,8 @@
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
if (self)
|
||||
{
|
||||
_format = RPixelFormatBGRA8Unorm;
|
||||
}
|
||||
return self;
|
||||
|
@ -34,7 +34,7 @@ extern MTLPixelFormat SelectOptimalPixelFormat(MTLPixelFormat fmt);
|
||||
@property (nonatomic, readwrite) CGRect frame;
|
||||
@property (nonatomic, readwrite) CGSize size;
|
||||
@property (nonatomic, readonly) ViewDrawState drawState;
|
||||
@property (nonatomic, readonly) struct video_shader* shader;
|
||||
@property (nonatomic, readonly) struct video_shader *shader;
|
||||
@property (nonatomic, readwrite) uint64_t frameCount;
|
||||
|
||||
- (void)setFilteringIndex:(int)index smooth:(bool)smooth;
|
||||
@ -60,14 +60,14 @@ extern MTLPixelFormat SelectOptimalPixelFormat(MTLPixelFormat fmt);
|
||||
|
||||
@interface MetalDriver : NSObject<MTKViewDelegate>
|
||||
|
||||
@property (nonatomic, readonly) video_viewport_t* viewport;
|
||||
@property (nonatomic, readonly) video_viewport_t *viewport;
|
||||
@property (nonatomic, readwrite) bool keepAspect;
|
||||
@property (nonatomic, readonly) MetalMenu* menu;
|
||||
@property (nonatomic, readonly) FrameView* frameView;
|
||||
@property (nonatomic, readonly) MenuDisplay* display;
|
||||
@property (nonatomic, readonly) Context* context;
|
||||
@property (nonatomic, readonly) Uniforms* viewportMVP;
|
||||
@property (nonatomic, readonly) Uniforms* viewportMVPNormalized;
|
||||
@property (nonatomic, readonly) MetalMenu *menu;
|
||||
@property (nonatomic, readonly) FrameView *frameView;
|
||||
@property (nonatomic, readonly) MenuDisplay *display;
|
||||
@property (nonatomic, readonly) Context *context;
|
||||
@property (nonatomic, readonly) Uniforms *viewportMVP;
|
||||
@property (nonatomic, readonly) Uniforms *viewportMVPNormalized;
|
||||
|
||||
- (instancetype)initWithVideo:(const video_info_t *)video
|
||||
input:(const input_driver_t **)input
|
||||
|
Loading…
x
Reference in New Issue
Block a user