mirror of
https://github.com/libretro/RetroArch
synced 2025-03-20 19:21:27 +00:00
(Metal common) Cleanups
This commit is contained in:
parent
86dccbf1d6
commit
13ac88c9df
@ -57,21 +57,12 @@
|
||||
@implementation MetalView
|
||||
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
- (void)keyDown:(NSEvent*)theEvent
|
||||
{
|
||||
}
|
||||
- (void)keyDown:(NSEvent*)theEvent { }
|
||||
#endif
|
||||
|
||||
/* Stop the annoying sound when pressing a key. */
|
||||
- (BOOL)acceptsFirstResponder
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isFlipped
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
- (BOOL)acceptsFirstResponder { return YES; }
|
||||
- (BOOL)isFlipped { return YES; }
|
||||
@end
|
||||
|
||||
#pragma mark - private categories
|
||||
@ -110,14 +101,14 @@
|
||||
|
||||
CAMetalLayer *_layer;
|
||||
|
||||
// render target layer state
|
||||
/* Render target layer state */
|
||||
id<MTLRenderPipelineState> _t_pipelineState;
|
||||
id<MTLRenderPipelineState> _t_pipelineStateNoAlpha;
|
||||
|
||||
id<MTLSamplerState> _samplerStateLinear;
|
||||
id<MTLSamplerState> _samplerStateNearest;
|
||||
|
||||
// other state
|
||||
/* other state */
|
||||
Uniforms _viewportMVP;
|
||||
}
|
||||
|
||||
@ -134,9 +125,7 @@
|
||||
_layer = (CAMetalLayer *)view.layer;
|
||||
|
||||
if (![self _initMetal])
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
_video = *video;
|
||||
_viewport = (video_viewport_t *)calloc(1, sizeof(video_viewport_t));
|
||||
@ -163,14 +152,12 @@
|
||||
|
||||
*input = NULL;
|
||||
*inputData = NULL;
|
||||
|
||||
// graphics display driver
|
||||
/* graphics display driver */
|
||||
_display = [[MenuDisplay alloc] initWithContext:_context];
|
||||
|
||||
// menu view
|
||||
/* menu view */
|
||||
_menu = [[MetalMenu alloc] initWithContext:_context];
|
||||
|
||||
// frame buffer view
|
||||
/* Framebuffer view */
|
||||
{
|
||||
ViewDescriptor *vd = [ViewDescriptor new];
|
||||
vd.format = _video.rgb32 ? RPixelFormatBGRX8Unorm : RPixelFormatB5G6R5Unorm;
|
||||
@ -181,7 +168,7 @@
|
||||
[_frameView setFilteringIndex:0 smooth:video->smooth];
|
||||
}
|
||||
|
||||
// overlay view
|
||||
/* Overlay view */
|
||||
_overlay = [[Overlay alloc] initWithContext:_context];
|
||||
|
||||
font_driver_init_osd((__bridge void *)self,
|
||||
@ -211,6 +198,9 @@
|
||||
library:_library];
|
||||
|
||||
{
|
||||
NSError *err;
|
||||
MTLRenderPipelineDescriptor *psd;
|
||||
MTLRenderPipelineColorAttachmentDescriptor *ca;
|
||||
MTLVertexDescriptor *vd = [MTLVertexDescriptor new];
|
||||
vd.attributes[0].offset = 0;
|
||||
vd.attributes[0].format = MTLVertexFormatFloat3;
|
||||
@ -218,10 +208,10 @@
|
||||
vd.attributes[1].format = MTLVertexFormatFloat2;
|
||||
vd.layouts[0].stride = sizeof(Vertex);
|
||||
|
||||
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
|
||||
psd = [MTLRenderPipelineDescriptor new];
|
||||
psd.label = @"Pipeline+Alpha";
|
||||
|
||||
MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0];
|
||||
ca = psd.colorAttachments[0];
|
||||
ca.pixelFormat = _layer.pixelFormat;
|
||||
ca.blendingEnabled = YES;
|
||||
ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
|
||||
@ -234,7 +224,7 @@
|
||||
psd.vertexFunction = [_library newFunctionWithName:@"basic_vertex_proj_tex"];
|
||||
psd.fragmentFunction = [_library newFunctionWithName:@"basic_fragment_proj_tex"];
|
||||
|
||||
NSError *err;
|
||||
|
||||
_t_pipelineState = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
|
||||
if (err != nil)
|
||||
{
|
||||
@ -271,19 +261,13 @@
|
||||
video_driver_set_size(_viewport->full_width, _viewport->full_height);
|
||||
_layer.drawableSize = CGSizeMake(width, height);
|
||||
video_driver_update_viewport(_viewport, forceFull, _keepAspect);
|
||||
|
||||
// update matrix
|
||||
_context.viewport = _viewport;
|
||||
|
||||
_context.viewport = _viewport; /* Update matrix */
|
||||
_viewportMVP.outputSize = simd_make_float2(_viewport->full_width, _viewport->full_height);
|
||||
}
|
||||
|
||||
#pragma mark - video
|
||||
|
||||
- (void)setVideo:(const video_info_t *)video
|
||||
{
|
||||
|
||||
}
|
||||
- (void)setVideo:(const video_info_t *)video { }
|
||||
|
||||
- (bool)renderFrame:(const void *)frame
|
||||
data:(void*)data
|
||||
@ -427,13 +411,9 @@
|
||||
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
|
||||
[rce setRenderPipelineState:_t_pipelineStateNoAlpha];
|
||||
if (_frameView.filter == RTextureFilterNearest)
|
||||
{
|
||||
[rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw];
|
||||
}
|
||||
else
|
||||
{
|
||||
[rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw];
|
||||
}
|
||||
[_frameView drawWithEncoder:rce];
|
||||
}
|
||||
[rce popDebugGroup];
|
||||
@ -455,13 +435,9 @@
|
||||
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
|
||||
[rce setRenderPipelineState:_t_pipelineState];
|
||||
if (_menu.view.filter == RTextureFilterNearest)
|
||||
{
|
||||
[rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw];
|
||||
}
|
||||
else
|
||||
{
|
||||
[rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw];
|
||||
}
|
||||
[_menu.view drawWithEncoder:rce];
|
||||
[rce popDebugGroup];
|
||||
}
|
||||
@ -476,31 +452,16 @@
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)_endFrame
|
||||
{
|
||||
[_context end];
|
||||
}
|
||||
|
||||
- (void)setNeedsResize
|
||||
{
|
||||
// TODO(sgc): resize all drawables
|
||||
}
|
||||
|
||||
- (void)setRotation:(unsigned)rotation
|
||||
{
|
||||
[_context setRotation:rotation];
|
||||
}
|
||||
|
||||
- (Uniforms *)viewportMVP
|
||||
{
|
||||
return &_viewportMVP;
|
||||
}
|
||||
- (void)_endFrame { [_context end]; }
|
||||
/* TODO/FIXME (sgc): resize*/
|
||||
- (void)setNeedsResize { }
|
||||
- (void)setRotation:(unsigned)rotation { [_context setRotation:rotation]; }
|
||||
- (Uniforms *)viewportMVP { return &_viewportMVP; }
|
||||
|
||||
#pragma mark - MTKViewDelegate
|
||||
|
||||
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size
|
||||
{
|
||||
NSLog(@"mtkView drawableSizeWillChange to: %f x %f",size.width,size.height);
|
||||
#ifdef HAVE_COCOATOUCH
|
||||
CGFloat scale = [[UIScreen mainScreen] scale];
|
||||
[self setViewportWidth:(unsigned int)view.bounds.size.width*scale height:(unsigned int)view.bounds.size.height*scale forceFull:NO allowRotate:YES];
|
||||
@ -509,11 +470,7 @@
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)drawInMTKView:(MTKView *)view
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)drawInMTKView:(MTKView *)view { }
|
||||
@end
|
||||
|
||||
@implementation MetalMenu
|
||||
@ -526,28 +483,21 @@
|
||||
- (instancetype)initWithContext:(Context *)context
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (bool)hasFrame
|
||||
{
|
||||
return _view != nil;
|
||||
}
|
||||
- (bool)hasFrame { return _view != nil; }
|
||||
|
||||
- (void)setEnabled:(bool)enabled
|
||||
{
|
||||
if (_enabled == enabled) return;
|
||||
if (_enabled == enabled)
|
||||
return;
|
||||
_enabled = enabled;
|
||||
_view.visible = enabled;
|
||||
}
|
||||
|
||||
- (bool)enabled
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
- (bool)enabled { return _enabled; }
|
||||
|
||||
- (void)updateWidth:(int)width
|
||||
height:(int)height
|
||||
@ -561,10 +511,8 @@
|
||||
if (!(CGSizeEqualToSize(_view.size, size) &&
|
||||
_view.format == format &&
|
||||
_view.filter == filter))
|
||||
{
|
||||
_view = nil;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_view)
|
||||
{
|
||||
@ -632,14 +580,14 @@ typedef struct MTLALIGN(16)
|
||||
@implementation FrameView
|
||||
{
|
||||
Context *_context;
|
||||
id<MTLTexture> _texture; // final render texture
|
||||
id<MTLTexture> _texture; /* final render texture */
|
||||
Vertex _v[4];
|
||||
VertexSlang _vertex[4];
|
||||
CGSize _size; // size of view in pixels
|
||||
CGSize _size; /* size of view in pixels */
|
||||
CGRect _frame;
|
||||
NSUInteger _bpp;
|
||||
|
||||
id<MTLTexture> _src; // src texture
|
||||
id<MTLTexture> _src; /* source texture */
|
||||
bool _srcDirty;
|
||||
|
||||
id<MTLSamplerState> _samplers[RARCH_FILTER_MAX][RARCH_WRAP_MAX];
|
||||
@ -662,13 +610,9 @@ typedef struct MTLALIGN(16)
|
||||
_bpp = RPixelFormatToBPP(_format);
|
||||
_filter = d.filter;
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
_drawState = ViewDrawStateEncoder;
|
||||
}
|
||||
else
|
||||
{
|
||||
_drawState = ViewDrawStateAll;
|
||||
}
|
||||
_visible = YES;
|
||||
_engine.mvp = matrix_proj_ortho(0, 1, 0, 1);
|
||||
[self _initSamplers];
|
||||
@ -677,7 +621,7 @@ typedef struct MTLALIGN(16)
|
||||
self.frame = CGRectMake(0, 0, 1, 1);
|
||||
resize_render_targets = YES;
|
||||
|
||||
// init slang vertex buffer
|
||||
/* Initialize slang vertex buffer */
|
||||
VertexSlang v[4] = {
|
||||
{simd_make_float4(0, 1, 0, 1), simd_make_float2(0, 1)},
|
||||
{simd_make_float4(1, 1, 0, 1), simd_make_float2(1, 1)},
|
||||
@ -691,10 +635,11 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
- (void)_initSamplers
|
||||
{
|
||||
int i;
|
||||
MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new];
|
||||
|
||||
/* Initialize samplers */
|
||||
for (unsigned i = 0; i < RARCH_WRAP_MAX; i++)
|
||||
for (i = 0; i < RARCH_WRAP_MAX; i++)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
@ -739,7 +684,8 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
- (void)setFilteringIndex:(int)index smooth:(bool)smooth
|
||||
{
|
||||
for (int i = 0; i < RARCH_WRAP_MAX; i++)
|
||||
int i;
|
||||
for (i = 0; i < RARCH_WRAP_MAX; i++)
|
||||
{
|
||||
if (smooth)
|
||||
_samplers[RARCH_FILTER_UNSPEC][i] = _samplers[RARCH_FILTER_LINEAR][i];
|
||||
@ -754,10 +700,10 @@ typedef struct MTLALIGN(16)
|
||||
return;
|
||||
|
||||
_size = size;
|
||||
|
||||
resize_render_targets = YES;
|
||||
|
||||
if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm)
|
||||
if ( _format != RPixelFormatBGRA8Unorm
|
||||
&& _format != RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint
|
||||
width:(NSUInteger)size.width
|
||||
@ -767,19 +713,14 @@ typedef struct MTLALIGN(16)
|
||||
}
|
||||
}
|
||||
|
||||
- (CGSize)size
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
- (CGSize)size { return _size; }
|
||||
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
if (CGRectEqualToRect(_frame, frame))
|
||||
return;
|
||||
|
||||
_frame = frame;
|
||||
|
||||
// update vertices
|
||||
/* update vertices */
|
||||
CGPoint o = frame.origin;
|
||||
CGSize s = frame.size;
|
||||
|
||||
@ -794,13 +735,12 @@ typedef struct MTLALIGN(16)
|
||||
{simd_make_float3(l, t, 0), simd_make_float2(0, 0)},
|
||||
{simd_make_float3(r, t, 0), simd_make_float2(1, 0)},
|
||||
};
|
||||
|
||||
_frame = frame;
|
||||
memcpy(_v, v, sizeof(_v));
|
||||
}
|
||||
|
||||
- (CGRect)frame
|
||||
{
|
||||
return _frame;
|
||||
}
|
||||
- (CGRect)frame { return _frame; }
|
||||
|
||||
- (void)_convertFormat
|
||||
{
|
||||
@ -837,8 +777,8 @@ typedef struct MTLALIGN(16)
|
||||
}
|
||||
|
||||
/* either no history, or we moved a texture of a different size in the front slot */
|
||||
if (_engine.frame.texture[0].size_data.x != _size.width ||
|
||||
_engine.frame.texture[0].size_data.y != _size.height)
|
||||
if ( _engine.frame.texture[0].size_data.x != _size.width
|
||||
|| _engine.frame.texture[0].size_data.y != _size.height)
|
||||
{
|
||||
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
|
||||
width:(NSUInteger)_size.width
|
||||
@ -851,13 +791,14 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
- (bool)readViewport:(uint8_t *)buffer isIdle:(bool)isIdle
|
||||
{
|
||||
bool res;
|
||||
bool enabled = _context.captureEnabled;
|
||||
if (!enabled)
|
||||
_context.captureEnabled = YES;
|
||||
|
||||
video_driver_cached_frame();
|
||||
|
||||
bool res = [_context readBackBuffer:buffer];
|
||||
res = [_context readBackBuffer:buffer];
|
||||
|
||||
if (!enabled)
|
||||
_context.captureEnabled = NO;
|
||||
@ -887,7 +828,8 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
[self _updateHistory];
|
||||
|
||||
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm)
|
||||
if ( _format == RPixelFormatBGRA8Unorm
|
||||
|| _format == RPixelFormatBGRX8Unorm)
|
||||
{
|
||||
id<MTLTexture> tex = _engine.frame.texture[0].view;
|
||||
[tex replaceRegion:MTLRegionMake2D(0, 0, (NSUInteger)_size.width, (NSUInteger)_size.height)
|
||||
@ -919,7 +861,9 @@ typedef struct MTLALIGN(16)
|
||||
width:(NSUInteger)_size.width
|
||||
height:(NSUInteger)_size.height
|
||||
mipmapped:false];
|
||||
td.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite | MTLTextureUsageRenderTarget;
|
||||
td.usage = MTLTextureUsageShaderRead
|
||||
| MTLTextureUsageShaderWrite
|
||||
| MTLTextureUsageRenderTarget;
|
||||
|
||||
for (i = 0; i < _shader->history_size + 1; i++)
|
||||
[self _initTexture:&_engine.frame.texture[i] withDescriptor:td];
|
||||
@ -939,7 +883,7 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
- (void)drawWithContext:(Context *)ctx
|
||||
{
|
||||
unsigned i;
|
||||
int i;
|
||||
_texture = _engine.frame.texture[0].view;
|
||||
[self _convertFormat];
|
||||
|
||||
@ -963,16 +907,17 @@ typedef struct MTLALIGN(16)
|
||||
rpd.colorAttachments[0].loadAction = MTLLoadActionDontCare;
|
||||
rpd.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||
|
||||
for (unsigned i = 0; i < _shader->passes; i++)
|
||||
for (i = 0; i < _shader->passes; i++)
|
||||
{
|
||||
int j;
|
||||
__unsafe_unretained id<MTLTexture> textures[SLANG_NUM_BINDINGS] = {NULL};
|
||||
id<MTLSamplerState> samplers[SLANG_NUM_BINDINGS] = {NULL};
|
||||
id<MTLRenderCommandEncoder> rce = nil;
|
||||
|
||||
BOOL backBuffer = (_engine.pass[i].rt.view == nil);
|
||||
|
||||
if (backBuffer)
|
||||
{
|
||||
rce = _context.rce;
|
||||
}
|
||||
else
|
||||
{
|
||||
rpd.colorAttachments[0].texture = _engine.pass[i].rt.view;
|
||||
@ -996,7 +941,7 @@ typedef struct MTLALIGN(16)
|
||||
_engine.pass[i].frame_direction = 1;
|
||||
#endif
|
||||
|
||||
for (unsigned j = 0; j < SLANG_CBUFFER_MAX; j++)
|
||||
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
|
||||
{
|
||||
id<MTLBuffer> buffer = _engine.pass[i].buffers[j];
|
||||
cbuffer_sem_t *buffer_sem = &_engine.pass[i].semantics.cbuffers[j];
|
||||
@ -1024,9 +969,6 @@ typedef struct MTLALIGN(16)
|
||||
}
|
||||
}
|
||||
|
||||
__unsafe_unretained id<MTLTexture> textures[SLANG_NUM_BINDINGS] = {NULL};
|
||||
id<MTLSamplerState> samplers[SLANG_NUM_BINDINGS] = {NULL};
|
||||
|
||||
texture_sem_t *texture_sem = _engine.pass[i].semantics.textures;
|
||||
while (texture_sem->stage_mask)
|
||||
{
|
||||
@ -1038,13 +980,9 @@ typedef struct MTLALIGN(16)
|
||||
}
|
||||
|
||||
if (backBuffer)
|
||||
{
|
||||
[rce setViewport:_engine.frame.viewport];
|
||||
}
|
||||
else
|
||||
{
|
||||
[rce setViewport:_engine.pass[i].viewport];
|
||||
}
|
||||
|
||||
[rce setFragmentTextures:textures withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)];
|
||||
[rce setFragmentSamplerStates:samplers withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)];
|
||||
@ -1052,9 +990,7 @@ typedef struct MTLALIGN(16)
|
||||
[rce drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
||||
|
||||
if (!backBuffer)
|
||||
{
|
||||
[rce endEncoding];
|
||||
}
|
||||
|
||||
_texture = _engine.pass[i].rt.view;
|
||||
}
|
||||
@ -1069,10 +1005,12 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
- (void)_updateRenderTargets
|
||||
{
|
||||
int i;
|
||||
NSUInteger width, height;
|
||||
if (!_shader || !resize_render_targets) return;
|
||||
|
||||
// release existing targets
|
||||
for (int i = 0; i < _shader->passes; i++)
|
||||
for (i = 0; i < _shader->passes; i++)
|
||||
{
|
||||
STRUCT_ASSIGN(_engine.pass[i].rt.view, nil);
|
||||
STRUCT_ASSIGN(_engine.pass[i].feedback.view, nil);
|
||||
@ -1080,9 +1018,10 @@ typedef struct MTLALIGN(16)
|
||||
memset(&_engine.pass[i].feedback, 0, sizeof(_engine.pass[i].feedback));
|
||||
}
|
||||
|
||||
NSUInteger width = (NSUInteger)_size.width, height = (NSUInteger)_size.height;
|
||||
width = (NSUInteger)_size.width;
|
||||
height = (NSUInteger)_size.height;
|
||||
|
||||
for (unsigned i = 0; i < _shader->passes; i++)
|
||||
for (i = 0; i < _shader->passes; i++)
|
||||
{
|
||||
struct video_shader_pass *shader_pass = &_shader->pass[i];
|
||||
|
||||
@ -1149,18 +1088,16 @@ typedef struct MTLALIGN(16)
|
||||
_engine.pass[i].viewport.zfar = 1.0;
|
||||
|
||||
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:fmt
|
||||
width:width
|
||||
height:height
|
||||
mipmapped:false];
|
||||
width:width height:height mipmapped:false];
|
||||
td.storageMode = MTLStorageModePrivate;
|
||||
td.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget;
|
||||
td.usage = MTLTextureUsageShaderRead
|
||||
| MTLTextureUsageRenderTarget;
|
||||
|
||||
[self _initTexture:&_engine.pass[i].rt withDescriptor:td];
|
||||
|
||||
if (shader_pass->feedback)
|
||||
{
|
||||
[self _initTexture:&_engine.pass[i].feedback withDescriptor:td];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_engine.pass[i].rt.size_data.x = width;
|
||||
@ -1175,11 +1112,13 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
- (void)_freeVideoShader:(struct video_shader *)shader
|
||||
{
|
||||
int i;
|
||||
if (!shader)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < GFX_MAX_SHADERS; i++)
|
||||
for (i = 0; i < GFX_MAX_SHADERS; i++)
|
||||
{
|
||||
int j;
|
||||
STRUCT_ASSIGN(_engine.pass[i].rt.view, nil);
|
||||
STRUCT_ASSIGN(_engine.pass[i].feedback.view, nil);
|
||||
memset(&_engine.pass[i].rt, 0, sizeof(_engine.pass[i].rt));
|
||||
@ -1187,13 +1126,13 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
STRUCT_ASSIGN(_engine.pass[i]._state, nil);
|
||||
|
||||
for (unsigned j = 0; j < SLANG_CBUFFER_MAX; j++)
|
||||
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
|
||||
{
|
||||
STRUCT_ASSIGN(_engine.pass[i].buffers[j], nil);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < GFX_MAX_TEXTURES; i++)
|
||||
for (i = 0; i < GFX_MAX_TEXTURES; i++)
|
||||
{
|
||||
STRUCT_ASSIGN(_engine.luts[i].view, nil);
|
||||
}
|
||||
@ -1213,7 +1152,7 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
@try
|
||||
{
|
||||
unsigned i;
|
||||
int i;
|
||||
texture_t *source = NULL;
|
||||
if (!video_shader_load_preset_into_shader(path.UTF8String, shader))
|
||||
return NO;
|
||||
@ -1395,15 +1334,17 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
for (i = 0; i < shader->luts; i++)
|
||||
{
|
||||
struct texture_image image = {0};
|
||||
struct texture_image image;
|
||||
image.pixels = NULL;
|
||||
image.width = 0;
|
||||
image.height = 0;
|
||||
image.supports_rgba = true;
|
||||
|
||||
if (!image_texture_load(&image, shader->lut[i].path))
|
||||
return NO;
|
||||
|
||||
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm
|
||||
width:image.width
|
||||
height:image.height
|
||||
width:image.width height:image.height
|
||||
mipmapped:shader->lut[i].mipmap];
|
||||
td.usage = MTLTextureUsageShaderRead;
|
||||
[self _initTexture:&_engine.luts[i] withDescriptor:td];
|
||||
@ -1421,10 +1362,8 @@ typedef struct MTLALIGN(16)
|
||||
@finally
|
||||
{
|
||||
if (shader)
|
||||
{
|
||||
[self _freeVideoShader:shader];
|
||||
}
|
||||
}
|
||||
|
||||
resize_render_targets = YES;
|
||||
init_history = YES;
|
||||
@ -1445,25 +1384,22 @@ typedef struct MTLALIGN(16)
|
||||
- (instancetype)initWithContext:(Context *)context
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (bool)loadImages:(const struct texture_image *)images count:(NSUInteger)count
|
||||
{
|
||||
int i;
|
||||
[self _freeImages];
|
||||
|
||||
_images = [NSMutableArray arrayWithCapacity:count];
|
||||
|
||||
NSUInteger needed = sizeof(SpriteVertex) * count * 4;
|
||||
if (!_vert || _vert.length < needed)
|
||||
{
|
||||
_vert = [_context.device newBufferWithLength:needed options:PLATFORM_METAL_RESOURCE_STORAGE_MODE];
|
||||
}
|
||||
|
||||
for (NSUInteger i = 0; i < count; i++)
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
_images[i] = [_context newTexture:images[i] mipmapped:NO];
|
||||
[self updateVertexX:0 y:0 w:1 h:1 index:i];
|
||||
@ -1478,6 +1414,8 @@ typedef struct MTLALIGN(16)
|
||||
|
||||
- (void)drawWithEncoder:(id<MTLRenderCommandEncoder>)rce
|
||||
{
|
||||
int i;
|
||||
NSUInteger count;
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
if (_vertDirty)
|
||||
{
|
||||
@ -1486,8 +1424,8 @@ typedef struct MTLALIGN(16)
|
||||
}
|
||||
#endif
|
||||
|
||||
NSUInteger count = _images.count;
|
||||
for (NSUInteger i = 0; i < count; ++i)
|
||||
count = _images.count;
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
NSUInteger offset = sizeof(SpriteVertex) * 4 * i;
|
||||
[rce setVertexBuffer:_vert offset:offset atIndex:BufferIndexPositions];
|
||||
@ -1538,10 +1476,7 @@ typedef struct MTLALIGN(16)
|
||||
_vertDirty = YES;
|
||||
}
|
||||
|
||||
- (void)_freeImages
|
||||
{
|
||||
_images = nil;
|
||||
}
|
||||
- (void)_freeImages { _images = nil; }
|
||||
|
||||
@end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user