From 51154d6907f44768f8cc2680fb5c5148c0f19808 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 28 Apr 2019 15:26:21 +1000 Subject: [PATCH 1/2] FramebufferShaderGen: Don't emit SV_SampleIndex when not using SSAA --- Source/Core/VideoCommon/FramebufferShaderGen.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Core/VideoCommon/FramebufferShaderGen.cpp b/Source/Core/VideoCommon/FramebufferShaderGen.cpp index c69f07c10d..dfb86d2be2 100644 --- a/Source/Core/VideoCommon/FramebufferShaderGen.cpp +++ b/Source/Core/VideoCommon/FramebufferShaderGen.cpp @@ -410,10 +410,13 @@ std::string GenerateFormatConversionShader(EFBReinterpretType convtype, u32 samp { std::stringstream ss; EmitSamplerDeclarations(ss, 0, 1, samples > 1); - EmitPixelMainDeclaration(ss, 1, 0, "float4", - GetAPIType() == APIType::D3D ? - "in float4 ipos : SV_Position, in uint isample : SV_SampleIndex, " : - ""); + EmitPixelMainDeclaration( + ss, 1, 0, "float4", + GetAPIType() == APIType::D3D ? + (g_ActiveConfig.bSSAA ? + "in float4 ipos : SV_Position, in uint isample : SV_SampleIndex, " : + "in float4 ipos : SV_Position, ") : + ""); ss << "{\n"; ss << " int layer = int(v_tex0.z);\n"; if (GetAPIType() == APIType::D3D) From 025767c9293a8ecf770daef063005491898206f6 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 28 Apr 2019 15:26:46 +1000 Subject: [PATCH 2/2] D3D: Set optional features after creating the device Fixes feature level 10.0 devices crashing during runtime. --- Source/Core/VideoBackends/D3D/D3DBase.cpp | 44 ++++++----------------- Source/Core/VideoBackends/D3D/D3DBase.h | 3 ++ Source/Core/VideoBackends/D3D/main.cpp | 19 ++++++++++ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/D3DBase.cpp b/Source/Core/VideoBackends/D3D/D3DBase.cpp index 0631ded2c0..6ed649263e 100644 --- a/Source/Core/VideoBackends/D3D/D3DBase.cpp +++ b/Source/Core/VideoBackends/D3D/D3DBase.cpp @@ -33,29 +33,6 @@ static ComPtr s_debug; static constexpr D3D_FEATURE_LEVEL s_supported_feature_levels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0}; -static bool SupportsS3TCTextures() -{ - UINT bc1_support, bc2_support, bc3_support; - if (FAILED(device->CheckFormatSupport(DXGI_FORMAT_BC1_UNORM, &bc1_support)) || - FAILED(device->CheckFormatSupport(DXGI_FORMAT_BC2_UNORM, &bc2_support)) || - FAILED(device->CheckFormatSupport(DXGI_FORMAT_BC3_UNORM, &bc3_support))) - { - return false; - } - - return ((bc1_support & bc2_support & bc3_support) & D3D11_FORMAT_SUPPORT_TEXTURE2D) != 0; -} - -static bool SupportsBPTCTextures() -{ - // Currently, we only care about BC7. This could be extended to BC6H in the future. - UINT bc7_support; - if (FAILED(device->CheckFormatSupport(DXGI_FORMAT_BC7_UNORM, &bc7_support))) - return false; - - return (bc7_support & D3D11_FORMAT_SUPPORT_TEXTURE2D) != 0; -} - bool Create(u32 adapter_index, bool enable_debug_layer) { PFN_D3D11_CREATE_DEVICE d3d11_create_device; @@ -145,17 +122,6 @@ bool Create(u32 adapter_index, bool enable_debug_layer) g_Config.backend_info.bSupportsLogicOp = false; } - g_Config.backend_info.bSupportsST3CTextures = SupportsS3TCTextures(); - g_Config.backend_info.bSupportsBPTCTextures = SupportsBPTCTextures(); - - // Features only supported with a FL11.0+ device. - const bool shader_model_5_supported = feature_level >= D3D_FEATURE_LEVEL_11_0; - g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported; - g_Config.backend_info.bSupportsBBox = shader_model_5_supported; - g_Config.backend_info.bSupportsFragmentStoresAndAtomics = shader_model_5_supported; - g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported; - g_Config.backend_info.bSupportsSSAA = shader_model_5_supported; - stateman = std::make_unique(); return true; } @@ -241,6 +207,16 @@ std::vector GetAAModes(u32 adapter_index) return aa_modes; } + +bool SupportsTextureFormat(DXGI_FORMAT format) +{ + UINT support; + if (FAILED(device->CheckFormatSupport(format, &support))) + return false; + + return (support & D3D11_FORMAT_SUPPORT_TEXTURE2D) != 0; +} + } // namespace D3D } // namespace DX11 diff --git a/Source/Core/VideoBackends/D3D/D3DBase.h b/Source/Core/VideoBackends/D3D/D3DBase.h index 5c92c9b18f..2afaf120e0 100644 --- a/Source/Core/VideoBackends/D3D/D3DBase.h +++ b/Source/Core/VideoBackends/D3D/D3DBase.h @@ -40,6 +40,9 @@ void Destroy(); // Returns a list of supported AA modes for the current device. std::vector GetAAModes(u32 adapter_index); +// Checks for support of the given texture format. +bool SupportsTextureFormat(DXGI_FORMAT format); + } // namespace D3D } // namespace DX11 diff --git a/Source/Core/VideoBackends/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp index d22b34c99a..d87965deff 100644 --- a/Source/Core/VideoBackends/D3D/main.cpp +++ b/Source/Core/VideoBackends/D3D/main.cpp @@ -87,6 +87,25 @@ void VideoBackend::FillBackendInfo() g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames(); g_Config.backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter); + + // Override optional features if we are actually booting. + if (D3D::device) + { + g_Config.backend_info.bSupportsST3CTextures = + D3D::SupportsTextureFormat(DXGI_FORMAT_BC1_UNORM) && + D3D::SupportsTextureFormat(DXGI_FORMAT_BC2_UNORM) && + D3D::SupportsTextureFormat(DXGI_FORMAT_BC3_UNORM); + g_Config.backend_info.bSupportsBPTCTextures = D3D::SupportsTextureFormat(DXGI_FORMAT_BC7_UNORM); + + // Features only supported with a FL11.0+ device. + const bool shader_model_5_supported = D3D::feature_level >= D3D_FEATURE_LEVEL_11_0; + g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported; + g_Config.backend_info.bSupportsBBox = shader_model_5_supported; + g_Config.backend_info.bSupportsFragmentStoresAndAtomics = shader_model_5_supported; + g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported; + g_Config.backend_info.bSupportsSSAA = shader_model_5_supported; + g_Config.backend_info.bSupportsGPUTextureDecoding = shader_model_5_supported; + } } bool VideoBackend::Initialize(const WindowSystemInfo& wsi)