mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-11-29 20:44:18 +01:00
check for pixel format support
This commit is contained in:
parent
69a36246fb
commit
ca256eb764
@ -73,8 +73,8 @@ LatteTextureMtl::LatteTextureMtl(class MetalRenderer* mtlRenderer, Latte::E_DIM
|
||||
desc->setArrayLength(effectiveBaseDepth);
|
||||
}
|
||||
|
||||
auto formatInfo = GetMtlPixelFormatInfo(format, isDepth);
|
||||
desc->setPixelFormat(formatInfo.pixelFormat);
|
||||
auto pixelFormat = GetMtlPixelFormat(format, isDepth, m_mtlr->GetPixelFormatSupport());
|
||||
desc->setPixelFormat(pixelFormat);
|
||||
|
||||
// HACK: even though the textures are never written to from a shader, we still need to use `ShaderWrite` usage to prevent pink lines over the screen
|
||||
MTL::TextureUsage usage = MTL::TextureUsageShaderRead | MTL::TextureUsageShaderWrite;
|
||||
|
@ -127,8 +127,8 @@ MTL::Texture* LatteTextureViewMtl::CreateSwizzledView(uint32 gpuSamplerSwizzle)
|
||||
swizzle.blue = GetMtlTextureSwizzle(compSelB);
|
||||
swizzle.alpha = GetMtlTextureSwizzle(compSelA);
|
||||
|
||||
auto formatInfo = GetMtlPixelFormatInfo(format, m_baseTexture->IsDepth());
|
||||
MTL::Texture* texture = m_baseTexture->GetTexture()->newTextureView(formatInfo.pixelFormat, textureType, NS::Range::Make(baseLevel, levelCount), NS::Range::Make(baseLayer, layerCount), swizzle);
|
||||
auto pixelFormat = GetMtlPixelFormat(format, m_baseTexture->IsDepth(), m_mtlr->GetPixelFormatSupport());
|
||||
MTL::Texture* texture = m_baseTexture->GetTexture()->newTextureView(pixelFormat, textureType, NS::Range::Make(baseLevel, levelCount), NS::Range::Make(baseLayer, layerCount), swizzle);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h"
|
||||
#include "Common/precompiled.h"
|
||||
#include "Metal/MTLDepthStencil.hpp"
|
||||
#include "Metal/MTLPixelFormat.hpp"
|
||||
#include "Metal/MTLRenderCommandEncoder.hpp"
|
||||
#include "Metal/MTLRenderPipeline.hpp"
|
||||
#include "Metal/MTLSampler.hpp"
|
||||
@ -74,7 +75,6 @@ std::map<Latte::E_GX2SURFFMT, MetalPixelFormatInfo> MTL_COLOR_FORMAT_TABLE = {
|
||||
};
|
||||
|
||||
std::map<Latte::E_GX2SURFFMT, MetalPixelFormatInfo> MTL_DEPTH_FORMAT_TABLE = {
|
||||
// TODO: one of these 2 formats is not supported on Apple silicon
|
||||
{Latte::E_GX2SURFFMT::D24_S8_UNORM, {MTL::PixelFormatDepth24Unorm_Stencil8, MetalDataType::NONE, 4, {1, 1}, true}},
|
||||
{Latte::E_GX2SURFFMT::D24_S8_FLOAT, {MTL::PixelFormatDepth32Float_Stencil8, MetalDataType::NONE, 4, {1, 1}, true}},
|
||||
{Latte::E_GX2SURFFMT::D32_S8_FLOAT, {MTL::PixelFormatDepth32Float_Stencil8, MetalDataType::NONE, 5, {1, 1}, true}},
|
||||
@ -105,6 +105,37 @@ const MetalPixelFormatInfo GetMtlPixelFormatInfo(Latte::E_GX2SURFFMT format, boo
|
||||
return formatInfo;
|
||||
}
|
||||
|
||||
MTL::PixelFormat GetMtlPixelFormat(Latte::E_GX2SURFFMT format, bool isDepth, const MetalPixelFormatSupport& pixelFormatSupport)
|
||||
{
|
||||
auto pixelFormat = GetMtlPixelFormatInfo(format, isDepth).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)
|
||||
{
|
||||
case MTL::PixelFormatB5G6R5Unorm:
|
||||
case MTL::PixelFormatA1BGR5Unorm:
|
||||
case MTL::PixelFormatABGR4Unorm:
|
||||
case MTL::PixelFormatBGR5A1Unorm:
|
||||
pixelFormat = MTL::PixelFormatRGBA8Unorm;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pixelFormatSupport.m_supportsDepth24Unorm_Stencil8 && pixelFormat == MTL::PixelFormatDepth24Unorm_Stencil8)
|
||||
pixelFormat = MTL::PixelFormatDepth32Float_Stencil8;
|
||||
|
||||
return pixelFormat;
|
||||
}
|
||||
|
||||
inline uint32 CeilDivide(uint32 a, uint32 b) {
|
||||
return (a + b - 1) / b;
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <Metal/Metal.hpp>
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/MetalCommon.h"
|
||||
|
||||
#include "Cafe/HW/Latte/ISA/LatteReg.h"
|
||||
#include "Cafe/HW/Latte/Core/LatteConst.h"
|
||||
//#include "Cafe/HW/Latte/Core/FetchShader.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Renderer.h"
|
||||
#include "Metal/MTLDepthStencil.hpp"
|
||||
#include "Metal/MTLRenderPipeline.hpp"
|
||||
#include "Metal/MTLSampler.hpp"
|
||||
#include "Metal/MTLTexture.hpp"
|
||||
|
||||
struct Uvec2 {
|
||||
uint32 x;
|
||||
@ -34,6 +30,8 @@ struct MetalPixelFormatInfo {
|
||||
|
||||
const MetalPixelFormatInfo GetMtlPixelFormatInfo(Latte::E_GX2SURFFMT format, bool isDepth);
|
||||
|
||||
MTL::PixelFormat GetMtlPixelFormat(Latte::E_GX2SURFFMT format, bool isDepth, const MetalPixelFormatSupport& pixelFormatSupport);
|
||||
|
||||
size_t GetMtlTextureBytesPerRow(Latte::E_GX2SURFFMT format, bool isDepth, uint32 width);
|
||||
|
||||
size_t GetMtlTextureBytesPerImage(Latte::E_GX2SURFFMT format, bool isDepth, uint32 height, size_t bytesPerRow);
|
||||
|
@ -1,8 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "Foundation/NSString.hpp"
|
||||
#include <Foundation/Foundation.hpp>
|
||||
#include <Metal/Metal.hpp>
|
||||
|
||||
struct MetalPixelFormatSupport
|
||||
{
|
||||
bool m_supportsR8Unorm_sRGB;
|
||||
bool m_supportsRG8Unorm_sRGB;
|
||||
bool m_supportsPacked16BitFormats;
|
||||
bool m_supportsDepth24Unorm_Stencil8;
|
||||
|
||||
MetalPixelFormatSupport() = default;
|
||||
MetalPixelFormatSupport(MTL::Device* device)
|
||||
{
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
#define MAX_MTL_BUFFERS 31
|
||||
// Buffer index 30 is reserved for the support buffer, buffer indices 27-29 are reserved for the helper shaders
|
||||
#define GET_MTL_VERTEX_BUFFER_INDEX(index) (MAX_MTL_BUFFERS - index - 5)
|
||||
|
@ -36,6 +36,7 @@ MetalRenderer::MetalRenderer()
|
||||
// Feature support
|
||||
m_hasUnifiedMemory = m_device->hasUnifiedMemory();
|
||||
m_isAppleGPU = m_device->supportsFamily(MTL::GPUFamilyApple1);
|
||||
m_pixelFormatSupport = MetalPixelFormatSupport(m_device);
|
||||
|
||||
// Resources
|
||||
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
|
||||
|
@ -371,6 +371,11 @@ public:
|
||||
return m_isAppleGPU;
|
||||
}
|
||||
|
||||
const MetalPixelFormatSupport& GetPixelFormatSupport() const
|
||||
{
|
||||
return m_pixelFormatSupport;
|
||||
}
|
||||
|
||||
MTL::StorageMode GetOptimalTextureStorageMode() const
|
||||
{
|
||||
return (m_isAppleGPU ? MTL::StorageModeShared : MTL::StorageModePrivate);
|
||||
@ -397,6 +402,7 @@ private:
|
||||
// Feature support
|
||||
bool m_hasUnifiedMemory;
|
||||
bool m_isAppleGPU;
|
||||
MetalPixelFormatSupport m_pixelFormatSupport;
|
||||
|
||||
// Managers and caches
|
||||
class MetalMemoryManager* m_memoryManager;
|
||||
|
Loading…
Reference in New Issue
Block a user