Cocoa Port: In the Metal framebuffer fetcher, further optimize 18-bit to 32-bit color conversions whenever the master brightness does not need to be applied, which is the most typical use case.

This commit is contained in:
rogerman 2017-11-28 00:53:50 -08:00
parent f0564cc4ac
commit cd6fbcd5ea
3 changed files with 58 additions and 32 deletions

View File

@ -60,9 +60,10 @@ typedef DisplayViewShaderProperties DisplayViewShaderProperties;
id<MTLLibrary> defaultLibrary;
id<MTLComputePipelineState> _fetch555Pipeline;
id<MTLComputePipelineState> _fetch555ConvertOnlyPipeline;
id<MTLComputePipelineState> _fetch666Pipeline;
id<MTLComputePipelineState> _fetch888Pipeline;
id<MTLComputePipelineState> _fetch555ConvertOnlyPipeline;
id<MTLComputePipelineState> _fetch666ConvertOnlyPipeline;
id<MTLComputePipelineState> deposterizePipeline;
id<MTLRenderPipelineState> hudPipeline;
id<MTLRenderPipelineState> hudRGBAPipeline;

View File

@ -66,9 +66,10 @@
commandQueue = [[device newCommandQueue] retain];
defaultLibrary = [[device newDefaultLibrary] retain];
_fetch555Pipeline = [[device newComputePipelineStateWithFunction:[defaultLibrary newFunctionWithName:@"nds_fetch555"] error:nil] retain];
_fetch555ConvertOnlyPipeline = [[device newComputePipelineStateWithFunction:[defaultLibrary newFunctionWithName:@"nds_fetch555ConvertOnly"] error:nil] retain];
_fetch666Pipeline = [[device newComputePipelineStateWithFunction:[defaultLibrary newFunctionWithName:@"nds_fetch666"] error:nil] retain];
_fetch888Pipeline = [[device newComputePipelineStateWithFunction:[defaultLibrary newFunctionWithName:@"nds_fetch888"] error:nil] retain];
_fetch555ConvertOnlyPipeline = [[device newComputePipelineStateWithFunction:[defaultLibrary newFunctionWithName:@"nds_fetch555ConvertOnly"] error:nil] retain];
_fetch666ConvertOnlyPipeline = [[device newComputePipelineStateWithFunction:[defaultLibrary newFunctionWithName:@"nds_fetch666ConvertOnly"] error:nil] retain];
deposterizePipeline = [[device newComputePipelineStateWithFunction:[defaultLibrary newFunctionWithName:@"src_filter_deposterize"] error:nil] retain];
size_t tw = GetNearestPositivePOT((uint32_t)[_fetch555Pipeline threadExecutionWidth]);
@ -227,9 +228,10 @@
[commandQueue release];
[defaultLibrary release];
[_fetch555Pipeline release];
[_fetch555ConvertOnlyPipeline release];
[_fetch666Pipeline release];
[_fetch888Pipeline release];
[_fetch555ConvertOnlyPipeline release];
[_fetch666ConvertOnlyPipeline release];
[deposterizePipeline release];
[hudPipeline release];
[hudRGBAPipeline release];
@ -477,22 +479,20 @@
id<MTLComputeCommandEncoder> cce = [cb computeCommandEncoder];
if (currentDisplayInfo.needConvertColorFormat[NDSDisplayID_Main] || currentDisplayInfo.needConvertColorFormat[NDSDisplayID_Touch] ||
currentDisplayInfo.needApplyMasterBrightness[NDSDisplayID_Main] || currentDisplayInfo.needApplyMasterBrightness[NDSDisplayID_Touch])
if (currentDisplayInfo.needApplyMasterBrightness[NDSDisplayID_Main] || currentDisplayInfo.needApplyMasterBrightness[NDSDisplayID_Touch])
{
switch (currentDisplayInfo.colorFormat)
if (currentDisplayInfo.colorFormat == NDSColorFormat_BGR555_Rev)
{
case NDSColorFormat_BGR555_Rev:
[cce setComputePipelineState:_fetch555Pipeline];
break;
case NDSColorFormat_BGR666_Rev:
[cce setComputePipelineState:_fetch666Pipeline];
break;
case NDSColorFormat_BGR888_Rev:
[cce setComputePipelineState:_fetch888Pipeline];
break;
[cce setComputePipelineState:_fetch555Pipeline];
}
else if ( (currentDisplayInfo.colorFormat == NDSColorFormat_BGR666_Rev) &&
(currentDisplayInfo.needConvertColorFormat[NDSDisplayID_Main] || currentDisplayInfo.needConvertColorFormat[NDSDisplayID_Touch]) )
{
[cce setComputePipelineState:_fetch666Pipeline];
}
else
{
[cce setComputePipelineState:_fetch888Pipeline];
}
if (isMainEnabled)
@ -559,13 +559,25 @@
isUsingFramebufferDirectlyTouch = false;
}
}
else
else if (currentDisplayInfo.colorFormat != NDSColorFormat_BGR888_Rev)
{
bool isPipelineStateSet = false;
if (currentDisplayInfo.colorFormat == NDSColorFormat_BGR555_Rev)
{
// 16-bit textures aren't handled natively in Metal for macOS, so we need to explicitly convert to 32-bit here.
[cce setComputePipelineState:_fetch555ConvertOnlyPipeline];
isPipelineStateSet = true;
}
else if ( (currentDisplayInfo.colorFormat == NDSColorFormat_BGR666_Rev) &&
(currentDisplayInfo.needConvertColorFormat[NDSDisplayID_Main] || currentDisplayInfo.needConvertColorFormat[NDSDisplayID_Touch]) )
{
[cce setComputePipelineState:_fetch666ConvertOnlyPipeline];
isPipelineStateSet = true;
}
if (isPipelineStateSet)
{
if (isMainEnabled)
{
if (!currentDisplayInfo.didPerformCustomRender[NDSDisplayID_Main])

View File

@ -443,19 +443,6 @@ kernel void nds_fetch555(const uint2 position [[thread_position_in_grid]],
outTexture.write(float4(outColor, 1.0f), position);
}
kernel void nds_fetch555ConvertOnly(const uint2 position [[thread_position_in_grid]],
const texture2d<ushort, access::read> inTexture [[texture(0)]],
texture2d<float, access::write> outTexture [[texture(1)]])
{
if ( (position.x > inTexture.get_width() - 1) || (position.y > inTexture.get_height() - 1) )
{
return;
}
const float4 outColor = unpack_unorm1555_to_unorm8888( (ushort)inTexture.read(position).r );
outTexture.write(float4(outColor.rgb, 1.0f), position);
}
kernel void nds_fetch666(const uint2 position [[thread_position_in_grid]],
const constant uchar *brightnessMode [[buffer(0)]],
const constant uchar *brightnessIntensity [[buffer(1)]],
@ -500,6 +487,32 @@ kernel void nds_fetch888(const uint2 position [[thread_position_in_grid]],
outTexture.write(float4(outColor, 1.0f), position);
}
kernel void nds_fetch555ConvertOnly(const uint2 position [[thread_position_in_grid]],
const texture2d<ushort, access::read> inTexture [[texture(0)]],
texture2d<float, access::write> outTexture [[texture(1)]])
{
if ( (position.x > inTexture.get_width() - 1) || (position.y > inTexture.get_height() - 1) )
{
return;
}
const float4 outColor = unpack_unorm1555_to_unorm8888( (ushort)inTexture.read(position).r );
outTexture.write(float4(outColor.rgb, 1.0f), position);
}
kernel void nds_fetch666ConvertOnly(const uint2 position [[thread_position_in_grid]],
const texture2d<float, access::read> inTexture [[texture(0)]],
texture2d<float, access::write> outTexture [[texture(1)]])
{
if ( (position.x > inTexture.get_width() - 1) || (position.y > inTexture.get_height() - 1) )
{
return;
}
const float3 outColor = inTexture.read(position).rgb * float3(255.0f/63.0f);
outTexture.write(float4(outColor, 1.0f), position);
}
float3 nds_apply_master_brightness(const float3 inColor, const uchar mode, const float intensity)
{
switch (mode)