(Metal) Small cleanups

This commit is contained in:
reallibretroadmin 2023-01-08 05:34:05 +01:00
parent 2b0c86f1f5
commit 29f165026a
3 changed files with 156 additions and 219 deletions

View File

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

View File

@ -37,20 +37,10 @@ static NSString *RPixelStrings[RPixelFormatCount];
NSUInteger RPixelFormatToBPP(RPixelFormat format)
{
switch (format)
{
case RPixelFormatBGRA8Unorm:
case RPixelFormatBGRX8Unorm:
return 4;
case RPixelFormatB5G6R5Unorm:
case RPixelFormatBGRA4Unorm:
return 2;
default:
RARCH_ERR("[Metal]: unknown RPixel format: %d\n", format);
return 4;
}
if ( format == RPixelFormatB5G6R5Unorm
|| format == RPixelFormatBGRA4Unorm )
return 2;
return 4;
}
static NSString *NSStringFromRPixelFormat(RPixelFormat format)
@ -69,44 +59,48 @@ static NSString *NSStringFromRPixelFormat(RPixelFormat format)
});
if (format >= RPixelFormatCount)
{
format = RPixelFormatInvalid;
}
return RPixelStrings[format];
}
matrix_float4x4 make_matrix_float4x4(const float *v)
{
simd_float4 P = simd_make_float4(v[0], v[1], v[2], v[3]);
simd_float4 P = simd_make_float4(v[0], v[1], v[2], v[3]);
v += 4;
simd_float4 Q = simd_make_float4(v[0], v[1], v[2], v[3]);
simd_float4 Q = simd_make_float4(v[0], v[1], v[2], v[3]);
v += 4;
simd_float4 R = simd_make_float4(v[0], v[1], v[2], v[3]);
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]);
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)
{
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);
#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,10 +233,8 @@ 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;
}
@ -252,7 +246,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
- (void)setViewport:(video_viewport_t *)viewport
{
_viewport = *viewport;
_viewport = *viewport;
_uniforms.outputSize = simd_make_float2(_viewport.full_width, _viewport.full_height);
}
@ -263,11 +257,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
- (void)setRotation:(unsigned)rotation
{
_rotation = 270 * rotation;
_rotation = 270 * rotation;
/* Calculate projection. */
_mvp_no_rot = matrix_proj_ortho(0, 1, 0, 1);
_mvp_no_rot = matrix_proj_ortho(0, 1, 0, 1);
bool allow_rotate = true;
if (!allow_rotate)
{
@ -276,9 +268,8 @@ 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;
_mvp = simd_mul(rot, _mvp_no_rot);
_uniforms.projectionMatrix = _mvp;
_uniformsNoRotate.projectionMatrix = _mvp_no_rot;
}
@ -331,24 +322,24 @@ matrix_float4x4 matrix_rotate_z(float rot)
vd.attributes[1].format = MTLVertexFormatFloat2;
vd.attributes[2].offset = offsetof(SpriteVertex, color);
vd.attributes[2].format = MTLVertexFormatFloat4;
vd.layouts[0].stride = sizeof(SpriteVertex);
vd.layouts[0].stride = sizeof(SpriteVertex);
return vd;
}
- (bool)_initClearState
{
MTLVertexDescriptor *vd = [self _spriteVertexDescriptor];
NSError *err;
MTLVertexDescriptor *vd = [self _spriteVertexDescriptor];
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
psd.label = @"clear_state";
MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0];
ca.pixelFormat = _layer.pixelFormat;
ca.pixelFormat = _layer.pixelFormat;
psd.vertexDescriptor = vd;
psd.vertexFunction = [_library newFunctionWithName:@"stock_vertex"];
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,24 +352,24 @@ matrix_float4x4 matrix_rotate_z(float rot)
- (bool)_initMenuStates
{
MTLVertexDescriptor *vd = [self _spriteVertexDescriptor];
NSError *err;
MTLVertexDescriptor *vd = [self _spriteVertexDescriptor];
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
psd.label = @"stock";
psd.label = @"stock";
MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0];
ca.pixelFormat = _layer.pixelFormat;
ca.blendingEnabled = NO;
ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
ca.pixelFormat = _layer.pixelFormat;
ca.blendingEnabled = NO;
ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
ca.destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
psd.sampleCount = 1;
psd.sampleCount = 1;
psd.vertexDescriptor = vd;
psd.vertexFunction = [_library newFunctionWithName:@"stock_vertex"];
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)
{
@ -386,8 +377,8 @@ matrix_float4x4 matrix_rotate_z(float rot)
return NO;
}
psd.label = @"stock_blend";
ca.blendingEnabled = YES;
psd.label = @"stock_blend";
ca.blendingEnabled = YES;
_states[VIDEO_SHADER_STOCK_BLEND][1] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil)
{
@ -397,10 +388,10 @@ matrix_float4x4 matrix_rotate_z(float rot)
MTLFunctionConstantValues *vals;
psd.label = @"snow_simple";
psd.label = @"snow_simple";
ca.blendingEnabled = YES;
{
vals = [MTLFunctionConstantValues new];
vals = [MTLFunctionConstantValues new];
float values[3] = {
1.25f, /* baseScale */
0.50f, /* density */
@ -418,10 +409,10 @@ matrix_float4x4 matrix_rotate_z(float rot)
return NO;
}
psd.label = @"snow";
psd.label = @"snow";
ca.blendingEnabled = YES;
{
vals = [MTLFunctionConstantValues new];
vals = [MTLFunctionConstantValues new];
float values[3] = {
3.50f, /* baseScale */
0.70f, /* density */
@ -439,9 +430,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
return NO;
}
psd.label = @"bokeh";
ca.blendingEnabled = YES;
psd.fragmentFunction = [_library newFunctionWithName:@"bokeh_fragment"];
psd.label = @"bokeh";
ca.blendingEnabled = YES;
psd.fragmentFunction = [_library newFunctionWithName:@"bokeh_fragment"];
_states[VIDEO_SHADER_MENU_5][1] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil)
{
@ -449,9 +440,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
return NO;
}
psd.label = @"snowflake";
ca.blendingEnabled = YES;
psd.fragmentFunction = [_library newFunctionWithName:@"snowflake_fragment"];
psd.label = @"snowflake";
ca.blendingEnabled = YES;
psd.fragmentFunction = [_library newFunctionWithName:@"snowflake_fragment"];
_states[VIDEO_SHADER_MENU_6][1] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil)
{
@ -459,32 +450,32 @@ matrix_float4x4 matrix_rotate_z(float rot)
return NO;
}
psd.label = @"ribbon";
ca.blendingEnabled = NO;
psd.vertexFunction = [_library newFunctionWithName:@"ribbon_vertex"];
psd.fragmentFunction = [_library newFunctionWithName:@"ribbon_fragment"];
_states[VIDEO_SHADER_MENU][0] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
psd.label = @"ribbon";
ca.blendingEnabled = NO;
psd.vertexFunction = [_library newFunctionWithName:@"ribbon_vertex"];
psd.fragmentFunction = [_library newFunctionWithName:@"ribbon_fragment"];
_states[VIDEO_SHADER_MENU][0] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil)
{
RARCH_ERR("[Metal]: error creating pipeline state %s\n", err.localizedDescription.UTF8String);
return NO;
}
psd.label = @"ribbon_blend";
ca.blendingEnabled = YES;
ca.sourceRGBBlendFactor = MTLBlendFactorOne;
ca.destinationRGBBlendFactor = MTLBlendFactorOne;
_states[VIDEO_SHADER_MENU][1] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
psd.label = @"ribbon_blend";
ca.blendingEnabled = YES;
ca.sourceRGBBlendFactor = MTLBlendFactorOne;
ca.destinationRGBBlendFactor = MTLBlendFactorOne;
_states[VIDEO_SHADER_MENU][1] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil)
{
RARCH_ERR("[Metal]: error creating pipeline state %s\n", err.localizedDescription.UTF8String);
return NO;
}
psd.label = @"ribbon_simple";
ca.blendingEnabled = NO;
psd.vertexFunction = [_library newFunctionWithName:@"ribbon_simple_vertex"];
psd.fragmentFunction = [_library newFunctionWithName:@"ribbon_simple_fragment"];
psd.label = @"ribbon_simple";
ca.blendingEnabled = NO;
psd.vertexFunction = [_library newFunctionWithName:@"ribbon_simple_vertex"];
psd.fragmentFunction = [_library newFunctionWithName:@"ribbon_simple_fragment"];
_states[VIDEO_SHADER_MENU_2][0] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil)
{
@ -492,10 +483,10 @@ matrix_float4x4 matrix_rotate_z(float rot)
return NO;
}
psd.label = @"ribbon_simple_blend";
ca.blendingEnabled = YES;
ca.sourceRGBBlendFactor = MTLBlendFactorOne;
ca.destinationRGBBlendFactor = MTLBlendFactorOne;
psd.label = @"ribbon_simple_blend";
ca.blendingEnabled = YES;
ca.sourceRGBBlendFactor = MTLBlendFactorOne;
ca.destinationRGBBlendFactor = MTLBlendFactorOne;
_states[VIDEO_SHADER_MENU_2][1] = [_device newRenderPipelineStateWithDescriptor:psd error:&err];
if (err != nil)
{
@ -510,9 +501,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
{
NSError *err = nil;
_filters[RPixelFormatBGRA4Unorm] = [Filter newFilterWithFunctionName:@"convert_bgra4444_to_bgra8888"
device:_device
library:_library
error:&err];
device:_device
library:_library
error:&err];
if (err)
{
RARCH_LOG("[Metal]: unable to create 'convert_bgra4444_to_bgra8888' conversion filter: %s\n",
@ -521,9 +512,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
}
_filters[RPixelFormatB5G6R5Unorm] = [Filter newFilterWithFunctionName:@"convert_rgb565_to_bgra8888"
device:_device
library:_library
error:&err];
device:_device
library:_library
error:&err];
if (err)
{
RARCH_LOG("[Metal]: unable to create 'convert_rgb565_to_bgra8888' conversion filter: %s\n",
@ -563,25 +554,23 @@ 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];
Texture *tex = [Texture new];
tex.texture = [self newTexture:image mipmapped:mipmapped];
tex.sampler = _samplers[filter];
return tex;
}
- (id<MTLTexture>)newTexture:(struct texture_image)image mipmapped:(bool)mipmapped
{
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
width:image.width
height:image.height
mipmapped:mipmapped];
width:image.width
height:image.height
mipmapped:mipmapped];
id<MTLTexture> t = [_device newTextureWithDescriptor:td];
[t replaceRegion:MTLRegionMake2D(0, 0, image.width, image.height)
mipmapLevel:0
withBytes:image.pixels
withBytes:image.pixels
bytesPerRow:4 * image.width];
if (mipmapped)
@ -598,9 +587,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
- (id<CAMetalDrawable>)nextDrawable
{
if (_drawable == nil)
{
_drawable = _layer.nextDrawable;
}
return _drawable;
}
@ -615,8 +602,9 @@ matrix_float4x4 matrix_rotate_z(float rot)
- (id<MTLCommandBuffer>)blitCommandBuffer
{
if (!_blitCommandBuffer) {
_blitCommandBuffer = [_commandQueue commandBuffer];
if (!_blitCommandBuffer)
{
_blitCommandBuffer = [_commandQueue commandBuffer];
_blitCommandBuffer.label = @"Blit command buffer";
}
return _blitCommandBuffer;
@ -663,10 +651,10 @@ matrix_float4x4 matrix_rotate_z(float rot)
mipmapLevel:0];
NSUInteger srcStride = _backBuffer.width * 4;
uint8_t const *src = tmp + (_viewport.y * srcStride);
uint8_t const *src = tmp + (_viewport.y * srcStride);
NSUInteger dstStride = _viewport.width * 3;
uint8_t *dst = buffer + (_viewport.height - 1) * dstStride;
uint8_t *dst = buffer + (_viewport.height - 1) * dstStride;
for (int y = 0; y < _viewport.height; y++, src += srcStride, dst -= dstStride)
{
@ -702,10 +690,8 @@ 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 = [_commandBuffer renderCommandEncoderWithDescriptor:rpd];
_rce.label = @"Frame command encoder";
}
return _rce;
@ -818,9 +804,7 @@ matrix_float4x4 matrix_rotate_z(float rot)
- (instancetype)initWithBuffer:(id<MTLBuffer>)src
{
if (self = [super init])
{
_src = src;
}
return self;
}
@ -848,7 +832,7 @@ static const NSUInteger kConstantAlignment = 4;
{
if (self = [super init])
{
_device = device;
_device = device;
_blockLen = blockLen;
}
return self;
@ -880,16 +864,15 @@ 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)
{
_head = [[BufferNode alloc] initWithBuffer:[_device newBufferWithLength:_blockLen options:opts]];
_head = [[BufferNode alloc] initWithBuffer:[_device newBufferWithLength:_blockLen options:opts]];
_length += _blockLen;
_current = _head;
_offset = 0;
_offset = 0;
}
if ([self _subAllocRange:range length:length])
@ -920,20 +903,20 @@ static const NSUInteger kConstantAlignment = 4;
- (void)_nextNode
{
_current = _current.next;
_offset = 0;
_offset = 0;
}
- (BOOL)_subAllocRange:(BufferRange *)range length:(NSUInteger)length
{
NSUInteger nextOffset = _offset + length;
NSUInteger nextOffset = _offset + length;
if (nextOffset <= _current.src.length)
{
_current.allocated = nextOffset;
_allocated += length;
range->data = _current.src.contents + _offset;
range->buffer = _current.src;
range->offset = _offset;
_offset = MTL_ALIGN_BUFFER(nextOffset);
_current.allocated = nextOffset;
_allocated += length;
range->data = _current.src.contents + _offset;
range->buffer = _current.src;
range->offset = _offset;
_offset = MTL_ALIGN_BUFFER(nextOffset);
return YES;
}
return NO;
@ -959,16 +942,14 @@ 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;
sd.magFilter = MTLSamplerMinMagFilterNearest;
sd.sAddressMode = MTLSamplerAddressModeClampToEdge;
sd.tAddressMode = MTLSamplerAddressModeClampToEdge;
sd.mipFilter = MTLSamplerMipFilterNotMipmapped;
MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new];
sd.minFilter = MTLSamplerMinMagFilterNearest;
sd.magFilter = MTLSamplerMinMagFilterNearest;
sd.sAddressMode = MTLSamplerAddressModeClampToEdge;
sd.tAddressMode = MTLSamplerAddressModeClampToEdge;
sd.mipFilter = MTLSamplerMipFilterNotMipmapped;
id<MTLSamplerState> sampler = [device newSamplerStateWithDescriptor:sd];
return [[Filter alloc] initWithKernel:kernel sampler:sampler];
@ -978,7 +959,7 @@ static const NSUInteger kConstantAlignment = 4;
{
if (self = [super init])
{
_kernel = kernel;
_kernel = kernel;
_sampler = sampler;
}
return self;
@ -996,12 +977,11 @@ static const NSUInteger kConstantAlignment = 4;
[self.delegate configure:ce];
MTLSize size = MTLSizeMake(16, 16, 1);
MTLSize size = MTLSizeMake(16, 16, 1);
MTLSize count = MTLSizeMake((tin.width + size.width + 1) / size.width, (tin.height + size.height + 1) / size.height,
1);
[ce dispatchThreadgroups:count threadsPerThreadgroup:size];
[ce endEncoding];
}
@ -1017,11 +997,10 @@ static const NSUInteger kConstantAlignment = 4;
[self.delegate configure:ce];
MTLSize size = MTLSizeMake(32, 1, 1);
MTLSize size = MTLSizeMake(32, 1, 1);
MTLSize count = MTLSizeMake((tin.length + 00) / 32, 1, 1);
[ce dispatchThreadgroups:count threadsPerThreadgroup:size];
[ce endEncoding];
}
@ -1108,30 +1087,19 @@ static const NSUInteger kConstantAlignment = 4;
- (MTLPrimitiveType)_toPrimitiveType:(enum gfx_display_prim_type)prim
{
switch (prim)
{
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
return MTLPrimitiveTypeTriangleStrip;
case GFX_DISPLAY_PRIM_TRIANGLES:
default:
/* Unexpected primitive type, defaulting to triangle */
break;
}
if (prim == GFX_DISPLAY_PRIM_TRIANGLESTRIP)
return MTLPrimitiveTypeTriangleStrip;
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->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);
switch (draw->pipeline_id)
@ -1264,22 +1232,19 @@ static const NSUInteger kConstantAlignment = 4;
{
self = [super init];
if (self)
{
_format = RPixelFormatBGRA8Unorm;
}
return self;
}
- (NSString *)debugDescription
{
#if defined(HAVE_COCOATOUCH)
NSString *sizeDesc = [NSString stringWithFormat:@"width: %f, height: %f",_size.width,_size.height];
NSString *sizeDesc = [NSString stringWithFormat:@"width: %f, height: %f",_size.width,_size.height];
#else
NSString *sizeDesc = NSStringFromSize(_size);
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;
}
@ -1302,21 +1266,17 @@ static const NSUInteger kConstantAlignment = 4;
self = [super init];
if (self)
{
_format = d.format;
_bpp = RPixelFormatToBPP(_format);
_filter = d.filter;
_context = c;
_visible = YES;
_format = d.format;
_bpp = RPixelFormatToBPP(_format);
_filter = d.filter;
_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);
self.size = d.size;
self.frame = CGRectMake(0, 0, 1, 1);
}
return self;
}
@ -1324,27 +1284,26 @@ static const NSUInteger kConstantAlignment = 4;
- (void)setSize:(CGSize)size
{
if (CGSizeEqualToSize(_size, size))
{
return;
}
_size = size;
{
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
width:(NSUInteger)size.width
height:(NSUInteger)size.height
mipmapped:NO];
width: (NSUInteger)size.width
height:(NSUInteger)size.height
mipmapped:NO];
td.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite;
_texture = [_context.device newTextureWithDescriptor:td];
}
if (_format != RPixelFormatBGRA8Unorm && _format != RPixelFormatBGRX8Unorm)
if ( _format != RPixelFormatBGRA8Unorm
&& _format != RPixelFormatBGRX8Unorm)
{
MTLTextureDescriptor *td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR16Uint
width:(NSUInteger)size.width
height:(NSUInteger)size.height
mipmapped:NO];
width:(NSUInteger)size.width
height:(NSUInteger)size.height
mipmapped:NO];
_src = [_context.device newTextureWithDescriptor:td];
}
}
@ -1357,16 +1316,14 @@ static const NSUInteger kConstantAlignment = 4;
- (void)setFrame:(CGRect)frame
{
if (CGRectEqualToRect(_frame, frame))
{
return;
}
_frame = frame;
_frame = frame;
float l = (float)CGRectGetMinX(frame);
float t = (float)CGRectGetMinY(frame);
float r = (float)CGRectGetMaxX(frame);
float b = (float)CGRectGetMaxY(frame);
float l = (float)CGRectGetMinX(frame);
float t = (float)CGRectGetMinY(frame);
float r = (float)CGRectGetMaxX(frame);
float b = (float)CGRectGetMaxY(frame);
Vertex v[4] = {
{simd_make_float3(l, b, 0), simd_make_float2(0, 1)},
@ -1384,7 +1341,8 @@ static const NSUInteger kConstantAlignment = 4;
- (void)_convertFormat
{
if (_format == RPixelFormatBGRA8Unorm || _format == RPixelFormatBGRX8Unorm)
if ( _format == RPixelFormatBGRA8Unorm
|| _format == RPixelFormatBGRX8Unorm)
return;
if (!_srcDirty)

View File

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