refactor pixel format support

This commit is contained in:
Samuliak 2024-09-06 17:38:19 +02:00
parent 4251f3fe55
commit 6a3bdd49e9
2 changed files with 26 additions and 27 deletions

View File

@ -1,4 +1,5 @@
#include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h"
#include "Cemu/Logging/CemuLogging.h"
#include "Common/precompiled.h"
#include "Metal/MTLDepthStencil.hpp"
#include "Metal/MTLPixelFormat.hpp"
@ -95,42 +96,40 @@ const MetalPixelFormatInfo GetMtlPixelFormatInfo(Latte::E_GX2SURFFMT format, boo
else
formatInfo = MTL_COLOR_FORMAT_TABLE[format];
if (formatInfo.pixelFormat == MTL::PixelFormatInvalid)
{
printf("invalid pixel format: %u\n", (uint32)format);
}
return formatInfo;
}
MTL::PixelFormat GetMtlPixelFormat(Latte::E_GX2SURFFMT format, bool isDepth, const MetalPixelFormatSupport& pixelFormatSupport)
{
auto pixelFormat = GetMtlPixelFormatInfo(format, isDepth).pixelFormat;
if (pixelFormat == MTL::PixelFormatInvalid)
cemuLog_logDebug(LogType::Force, "invalid pixel format {}\n", pixelFormat);
if (!pixelFormatSupport.m_supportsR8Unorm_sRGB && pixelFormat == MTL::PixelFormatR8Unorm_sRGB)
pixelFormat = MTL::PixelFormatRGBA8Unorm_sRGB;
if (!pixelFormatSupport.m_supportsRG8Unorm_sRGB && pixelFormat == MTL::PixelFormatRG8Unorm_sRGB)
pixelFormat = MTL::PixelFormatRGBA8Unorm_sRGB;
if (!pixelFormatSupport.m_supportsPacked16BitFormats)
switch (pixelFormat)
{
switch (pixelFormat)
{
case MTL::PixelFormatB5G6R5Unorm:
case MTL::PixelFormatA1BGR5Unorm:
case MTL::PixelFormatABGR4Unorm:
case MTL::PixelFormatBGR5A1Unorm:
pixelFormat = MTL::PixelFormatRGBA8Unorm;
break;
default:
break;
}
case MTL::PixelFormatR8Unorm_sRGB:
if (!pixelFormatSupport.m_supportsR8Unorm_sRGB)
return MTL::PixelFormatRGBA8Unorm_sRGB;
break;
case MTL::PixelFormatRG8Unorm_sRGB:
if (!pixelFormatSupport.m_supportsRG8Unorm_sRGB)
return MTL::PixelFormatRGBA8Unorm_sRGB;
break;
case MTL::PixelFormatB5G6R5Unorm:
case MTL::PixelFormatA1BGR5Unorm:
case MTL::PixelFormatABGR4Unorm:
case MTL::PixelFormatBGR5A1Unorm:
if (!pixelFormatSupport.m_supportsPacked16BitFormats)
return MTL::PixelFormatRGBA8Unorm;
break;
case MTL::PixelFormatDepth24Unorm_Stencil8:
if (!pixelFormatSupport.m_supportsDepth24Unorm_Stencil8)
return MTL::PixelFormatDepth32Float_Stencil8;
break;
default:
break;
}
if (!pixelFormatSupport.m_supportsDepth24Unorm_Stencil8 && pixelFormat == MTL::PixelFormatDepth24Unorm_Stencil8)
pixelFormat = MTL::PixelFormatDepth32Float_Stencil8;
return pixelFormat;
}

View File

@ -18,7 +18,7 @@ struct MetalPixelFormatSupport
m_supportsR8Unorm_sRGB = device->supportsFamily(MTL::GPUFamilyApple1);
m_supportsRG8Unorm_sRGB = device->supportsFamily(MTL::GPUFamilyApple1);
m_supportsPacked16BitFormats = device->supportsFamily(MTL::GPUFamilyApple1);
m_supportsDepth24Unorm_Stencil8 = device->supportsFamily(MTL::GPUFamilyMac2);
m_supportsDepth24Unorm_Stencil8 = device->depth24Stencil8PixelFormatSupported();
}
};