VideoCommon: Move backend_info out of VideoConfig struct.

This commit is contained in:
Jordan Woyak
2025-03-07 14:43:39 -06:00
parent 99e686de34
commit c18c039089
62 changed files with 741 additions and 788 deletions

View File

@ -334,7 +334,7 @@ void Metal::Gfx::ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool col
static_cast<double>((color >> 24) & 0xFF) / 255.0);
// clang-format on
float z_normalized = static_cast<float>(z & 0xFFFFFF) / 16777216.0f;
if (!g_Config.backend_info.bSupportsReversedDepthRange)
if (!g_backend_info.bSupportsReversedDepthRange)
z_normalized = 1.f - z_normalized;
g_state_tracker->BeginClearRenderPass(clear_color, z_normalized);
return;

View File

@ -81,8 +81,8 @@ bool Metal::VideoBackend::Initialize(const WindowSystemInfo& wsi)
return false;
}
Util::PopulateBackendInfo(&g_Config);
Util::PopulateBackendInfoAdapters(&g_Config, devs);
Util::PopulateBackendInfo(&g_backend_info);
Util::PopulateBackendInfoAdapters(&g_backend_info, devs);
// Since we haven't called InitializeShared yet, iAdapter may be out of range,
// so we have to check it ourselves.
@ -93,7 +93,7 @@ bool Metal::VideoBackend::Initialize(const WindowSystemInfo& wsi)
selected_adapter_index = 0;
}
MRCOwned<id<MTLDevice>> adapter = std::move(devs[selected_adapter_index]);
Util::PopulateBackendInfoFeatures(&g_Config, adapter);
Util::PopulateBackendInfoFeatures(g_Config, &g_backend_info, adapter);
#if TARGET_OS_OSX
// This should be available on all macOS 13.3+ systems but when using OCLP drivers, some devices
@ -143,16 +143,16 @@ void Metal::VideoBackend::InitBackendInfo(const WindowSystemInfo& wsi)
{
@autoreleasepool
{
Util::PopulateBackendInfo(&g_Config);
Util::PopulateBackendInfo(&g_backend_info);
auto adapters = Util::GetAdapterList();
Util::PopulateBackendInfoAdapters(&g_Config, adapters);
Util::PopulateBackendInfoAdapters(&g_backend_info, adapters);
if (!adapters.empty())
{
// Use the selected adapter, or the first to fill features.
size_t index = static_cast<size_t>(g_Config.iAdapter);
if (index >= adapters.size())
index = 0;
Util::PopulateBackendInfoFeatures(&g_Config, adapters[index]);
Util::PopulateBackendInfoFeatures(g_Config, &g_backend_info, adapters[index]);
}
}
}
@ -165,9 +165,9 @@ void Metal::VideoBackend::PrepareWindow(WindowSystemInfo& wsi)
NSView* view = static_cast<NSView*>(wsi.render_surface);
CAMetalLayer* layer = [CAMetalLayer layer];
Util::PopulateBackendInfo(&g_Config);
Util::PopulateBackendInfo(&g_backend_info);
if (g_Config.backend_info.bSupportsHDROutput && g_Config.bHDR)
if (g_backend_info.bSupportsHDROutput && g_Config.bHDR)
{
[layer setWantsExtendedDynamicRangeContent:YES];
[layer setPixelFormat:MTLPixelFormatRGBA16Float];

View File

@ -57,7 +57,7 @@ void Metal::ObjectCache::Shutdown()
static MTLCompareFunction Convert(CompareMode mode)
{
const bool invert_depth = !g_Config.backend_info.bSupportsReversedDepthRange;
const bool invert_depth = !g_backend_info.bSupportsReversedDepthRange;
switch (mode)
{
case CompareMode::Never: return MTLCompareFunctionNever;

View File

@ -737,9 +737,8 @@ void Metal::StateTracker::PrepareRender()
m_current.depth_stencil = pipe->DepthStencil();
[enc setDepthStencilState:g_object_cache->GetDepthStencil(m_current.depth_stencil)];
}
MTLDepthClipMode clip = is_gx && g_ActiveConfig.backend_info.bSupportsDepthClamp ?
MTLDepthClipModeClamp :
MTLDepthClipModeClip;
MTLDepthClipMode clip =
is_gx && g_backend_info.bSupportsDepthClamp ? MTLDepthClipModeClamp : MTLDepthClipModeClip;
if (clip != m_current.depth_clip_mode)
{
m_current.depth_clip_mode = clip;

View File

@ -41,10 +41,11 @@ struct Viewport
/// Gets the list of Metal devices, ordered so the system default device is first
std::vector<MRCOwned<id<MTLDevice>>> GetAdapterList();
void PopulateBackendInfo(VideoConfig* config);
void PopulateBackendInfoAdapters(VideoConfig* config,
void PopulateBackendInfo(BackendInfo* backend_info);
void PopulateBackendInfoAdapters(BackendInfo* backend_info,
const std::vector<MRCOwned<id<MTLDevice>>>& adapters);
void PopulateBackendInfoFeatures(VideoConfig* config, id<MTLDevice> device);
void PopulateBackendInfoFeatures(const VideoConfig& config, BackendInfo* backend_info,
id<MTLDevice> device);
AbstractTextureFormat ToAbstract(MTLPixelFormat format);
MTLPixelFormat FromAbstract(AbstractTextureFormat format);

View File

@ -36,58 +36,58 @@ std::vector<MRCOwned<id<MTLDevice>>> Metal::Util::GetAdapterList()
return list;
}
void Metal::Util::PopulateBackendInfo(VideoConfig* config)
void Metal::Util::PopulateBackendInfo(BackendInfo* backend_info)
{
config->backend_info.api_type = APIType::Metal;
config->backend_info.bUsesLowerLeftOrigin = false;
config->backend_info.bSupportsExclusiveFullscreen = false;
config->backend_info.bSupportsDualSourceBlend = true;
config->backend_info.bSupportsPrimitiveRestart = true;
config->backend_info.bSupportsGeometryShaders = false;
config->backend_info.bSupportsComputeShaders = true;
config->backend_info.bSupports3DVision = false;
config->backend_info.bSupportsEarlyZ = true;
config->backend_info.bSupportsBindingLayout = true;
config->backend_info.bSupportsBBox = true;
config->backend_info.bSupportsGSInstancing = false;
config->backend_info.bSupportsPostProcessing = true;
config->backend_info.bSupportsPaletteConversion = true;
config->backend_info.bSupportsClipControl = true;
config->backend_info.bSupportsSSAA = true;
config->backend_info.bSupportsFragmentStoresAndAtomics = true;
config->backend_info.bSupportsReversedDepthRange = false;
config->backend_info.bSupportsLogicOp = false;
config->backend_info.bSupportsMultithreading = false;
config->backend_info.bSupportsGPUTextureDecoding = true;
config->backend_info.bSupportsCopyToVram = true;
config->backend_info.bSupportsBitfield = true;
config->backend_info.bSupportsDynamicSamplerIndexing = true;
config->backend_info.bSupportsFramebufferFetch = false;
config->backend_info.bSupportsBackgroundCompiling = true;
config->backend_info.bSupportsLargePoints = true;
config->backend_info.bSupportsPartialDepthCopies = true;
config->backend_info.bSupportsDepthReadback = true;
config->backend_info.bSupportsShaderBinaries = false;
config->backend_info.bSupportsPipelineCacheData = false;
config->backend_info.bSupportsCoarseDerivatives = false;
config->backend_info.bSupportsTextureQueryLevels = true;
config->backend_info.bSupportsLodBiasInSampler = false;
config->backend_info.bSupportsSettingObjectNames = true;
backend_info->api_type = APIType::Metal;
backend_info->bUsesLowerLeftOrigin = false;
backend_info->bSupportsExclusiveFullscreen = false;
backend_info->bSupportsDualSourceBlend = true;
backend_info->bSupportsPrimitiveRestart = true;
backend_info->bSupportsGeometryShaders = false;
backend_info->bSupportsComputeShaders = true;
backend_info->bSupports3DVision = false;
backend_info->bSupportsEarlyZ = true;
backend_info->bSupportsBindingLayout = true;
backend_info->bSupportsBBox = true;
backend_info->bSupportsGSInstancing = false;
backend_info->bSupportsPostProcessing = true;
backend_info->bSupportsPaletteConversion = true;
backend_info->bSupportsClipControl = true;
backend_info->bSupportsSSAA = true;
backend_info->bSupportsFragmentStoresAndAtomics = true;
backend_info->bSupportsReversedDepthRange = false;
backend_info->bSupportsLogicOp = false;
backend_info->bSupportsMultithreading = false;
backend_info->bSupportsGPUTextureDecoding = true;
backend_info->bSupportsCopyToVram = true;
backend_info->bSupportsBitfield = true;
backend_info->bSupportsDynamicSamplerIndexing = true;
backend_info->bSupportsFramebufferFetch = false;
backend_info->bSupportsBackgroundCompiling = true;
backend_info->bSupportsLargePoints = true;
backend_info->bSupportsPartialDepthCopies = true;
backend_info->bSupportsDepthReadback = true;
backend_info->bSupportsShaderBinaries = false;
backend_info->bSupportsPipelineCacheData = false;
backend_info->bSupportsCoarseDerivatives = false;
backend_info->bSupportsTextureQueryLevels = true;
backend_info->bSupportsLodBiasInSampler = false;
backend_info->bSupportsSettingObjectNames = true;
// Metal requires multisample resolve to be done on a render pass
config->backend_info.bSupportsPartialMultisampleResolve = false;
config->backend_info.bSupportsDynamicVertexLoader = true;
config->backend_info.bSupportsVSLinePointExpand = true;
config->backend_info.bSupportsHDROutput =
backend_info->bSupportsPartialMultisampleResolve = false;
backend_info->bSupportsDynamicVertexLoader = true;
backend_info->bSupportsVSLinePointExpand = true;
backend_info->bSupportsHDROutput =
1.0 < [[NSScreen deepestScreen] maximumPotentialExtendedDynamicRangeColorComponentValue];
}
void Metal::Util::PopulateBackendInfoAdapters(VideoConfig* config,
void Metal::Util::PopulateBackendInfoAdapters(BackendInfo* backend_info,
const std::vector<MRCOwned<id<MTLDevice>>>& adapters)
{
config->backend_info.Adapters.clear();
backend_info->Adapters.clear();
for (id<MTLDevice> adapter : adapters)
{
config->backend_info.Adapters.push_back([[adapter name] UTF8String]);
backend_info->Adapters.push_back([[adapter name] UTF8String]);
}
}
@ -238,7 +238,8 @@ fragment float4 is_helper_test() {
return DetectionResult::Unsure;
}
void Metal::Util::PopulateBackendInfoFeatures(VideoConfig* config, id<MTLDevice> device)
void Metal::Util::PopulateBackendInfoFeatures(const VideoConfig& config, BackendInfo* backend_info,
id<MTLDevice> device)
{
// Initialize DriverDetails first so we can use it later
DriverDetails::Vendor vendor = DriverDetails::VENDOR_UNKNOWN;
@ -257,9 +258,9 @@ void Metal::Util::PopulateBackendInfoFeatures(VideoConfig* config, id<MTLDevice>
DriverDetails::Family::UNKNOWN, std::move(name));
#if TARGET_OS_OSX
config->backend_info.bSupportsDepthClamp = true;
config->backend_info.bSupportsST3CTextures = true;
config->backend_info.bSupportsBPTCTextures = true;
backend_info->bSupportsDepthClamp = true;
backend_info->bSupportsST3CTextures = true;
backend_info->bSupportsBPTCTextures = true;
#else
bool supports_apple4 = false;
bool supports_bcn = false;
@ -269,21 +270,21 @@ void Metal::Util::PopulateBackendInfoFeatures(VideoConfig* config, id<MTLDevice>
supports_apple4 = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1];
if (@available(iOS 16.4, *))
supports_bcn = [device supportsBCTextureCompression];
config->backend_info.bSupportsDepthClamp = supports_apple4;
config->backend_info.bSupportsST3CTextures = supports_bcn;
config->backend_info.bSupportsBPTCTextures = supports_bcn;
backend_info->bSupportsDepthClamp = supports_apple4;
backend_info->bSupportsST3CTextures = supports_bcn;
backend_info->bSupportsBPTCTextures = supports_bcn;
config->backend_info.bSupportsFramebufferFetch = true;
backend_info->bSupportsFramebufferFetch = true;
#endif
config->backend_info.AAModes.clear();
backend_info->AAModes.clear();
for (u32 i = 1; i <= 64; i <<= 1)
{
if ([device supportsTextureSampleCount:i])
config->backend_info.AAModes.push_back(i);
backend_info->AAModes.push_back(i);
}
switch (config->iManuallyUploadBuffers)
switch (config.iManuallyUploadBuffers)
{
case TriState::Off:
g_features.manual_buffer_upload = false;
@ -310,7 +311,7 @@ void Metal::Util::PopulateBackendInfoFeatures(VideoConfig* config, id<MTLDevice>
// Requires SIMD-scoped reduction operations
g_features.subgroup_ops =
[device supportsFamily:MTLGPUFamilyMac2] || [device supportsFamily:MTLGPUFamilyApple7];
config->backend_info.bSupportsFramebufferFetch = [device supportsFamily:MTLGPUFamilyApple1];
backend_info->bSupportsFramebufferFetch = [device supportsFamily:MTLGPUFamilyApple1];
}
if (g_features.subgroup_ops)
{
@ -325,10 +326,10 @@ void Metal::Util::PopulateBackendInfoFeatures(VideoConfig* config, id<MTLDevice>
#if TARGET_OS_OSX
if (@available(macOS 11, *))
if (vendor == DriverDetails::VENDOR_INTEL)
config->backend_info.bSupportsFramebufferFetch |= DetectIntelGPUFBFetch(device);
backend_info->bSupportsFramebufferFetch |= DetectIntelGPUFBFetch(device);
#endif
if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DYNAMIC_SAMPLER_INDEXING))
config->backend_info.bSupportsDynamicSamplerIndexing = false;
backend_info->bSupportsDynamicSamplerIndexing = false;
}
// clang-format off