From 299fd3d5ad790eb2fcb8531d42ac56780f7e0e06 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 30 Mar 2024 02:21:13 +1000 Subject: [PATCH] GS/DX11: Re-enable FL10 support with a warning --- bin/resources/shaders/common/fxaa.fx | 18 ++++------ pcsx2/GS/Renderers/DX11/D3D.cpp | 8 +++++ pcsx2/GS/Renderers/DX11/GSDevice11.cpp | 47 ++++++++++++++++++-------- pcsx2/GS/Renderers/DX11/GSDevice11.h | 5 ++- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/bin/resources/shaders/common/fxaa.fx b/bin/resources/shaders/common/fxaa.fx index 2b192c6a6c..f7ad22e06e 100644 --- a/bin/resources/shaders/common/fxaa.fx +++ b/bin/resources/shaders/common/fxaa.fx @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team // SPDX-License-Identifier: LGPL-3.0+ -#ifndef FXAA_HLSL_5 - #define FXAA_HLSL_5 0 +#ifndef FXAA_HLSL + #define FXAA_HLSL 0 #endif #ifndef FXAA_GLSL_130 #define FXAA_GLSL_130 0 @@ -31,7 +31,7 @@ layout(location = 0) in vec2 PSin_t; layout(location = 0) out vec4 SV_Target0; layout(set = 0, binding = 0) uniform sampler2D TextureSampler; -#elif (FXAA_HLSL_5 == 1) +#elif (FXAA_HLSL == 1) Texture2D Texture : register(t0); SamplerState TextureSampler : register(s0); @@ -60,12 +60,10 @@ static constexpr sampler MAIN_SAMPLER(coord::normalized, address::clamp_to_edge, [FXAA CODE SECTION] ------------------------------------------------------------------------------*/ -#if (FXAA_HLSL_5 == 1) +#if (FXAA_HLSL == 1) struct FxaaTex { SamplerState smpl; Texture2D tex; }; #define FxaaTexTop(t, p) t.tex.SampleLevel(t.smpl, p, 0.0) #define FxaaTexOff(t, p, o, r) t.tex.SampleLevel(t.smpl, p, 0.0, o) -#define FxaaTexAlpha4(t, p) t.tex.GatherAlpha(t.smpl, p) -#define FxaaTexOffAlpha4(t, p, o) t.tex.GatherAlpha(t.smpl, p, o) #define FxaaDiscard clip(-1) #define FxaaSat(x) saturate(x) @@ -84,8 +82,6 @@ struct FxaaTex { SamplerState smpl; Texture2D tex; }; #define FxaaTex texture2d #define FxaaTexTop(t, p) t.sample(MAIN_SAMPLER, p) #define FxaaTexOff(t, p, o, r) t.sample(MAIN_SAMPLER, p, o) -#define FxaaTexAlpha4(t, p) t.gather(MAIN_SAMPLER, p, 0, component::w) -#define FxaaTexOffAlpha4(t, p, o) t.gather(MAIN_SAMPLER, p, o, component::w) #define FxaaDiscard discard_fragment() #define FxaaSat(x) saturate(x) #endif @@ -444,14 +440,14 @@ float4 FxaaPixelShader(float2 pos, FxaaTex tex, float2 fxaaRcpFrame, float fxaaS #if (FXAA_GLSL_130 == 1 || FXAA_GLSL_VK == 1) float4 FxaaPass(float4 FxaaColor, float2 uv0) -#elif (FXAA_HLSL_5 == 1) +#elif (FXAA_HLSL == 1) float4 FxaaPass(float4 FxaaColor : COLOR0, float2 uv0 : TEXCOORD0) #elif defined(__METAL_VERSION__) float4 FxaaPass(float4 FxaaColor, float2 uv0, texture2d tex) #endif { - #if (FXAA_HLSL_5 == 1) + #if (FXAA_HLSL == 1) FxaaTex tex; tex.tex = Texture; tex.smpl = TextureSampler; @@ -485,7 +481,7 @@ void main() SV_Target0 = float4(color.rgb, 1.0); } -#elif (FXAA_HLSL_5 == 1) +#elif (FXAA_HLSL == 1) PS_OUTPUT main(VS_OUTPUT input) { PS_OUTPUT output; diff --git a/pcsx2/GS/Renderers/DX11/D3D.cpp b/pcsx2/GS/Renderers/DX11/D3D.cpp index da4e8c7d8d..b37d959e02 100644 --- a/pcsx2/GS/Renderers/DX11/D3D.cpp +++ b/pcsx2/GS/Renderers/DX11/D3D.cpp @@ -359,6 +359,7 @@ GSRendererType D3D::GetPreferredRenderer() static const D3D_FEATURE_LEVEL check[] = { D3D_FEATURE_LEVEL_12_0, D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_0, }; D3D_FEATURE_LEVEL feature_level; @@ -484,6 +485,13 @@ wil::com_ptr_nothrow D3D::CompileShader(D3D::ShaderType type, D3D_FEAT const char* target; switch (feature_level) { + case D3D_FEATURE_LEVEL_10_0: + { + static constexpr std::array targets = {{"vs_4_0", "ps_4_0", "cs_4_0"}}; + target = targets[static_cast(type)]; + } + break; + case D3D_FEATURE_LEVEL_11_0: { static constexpr std::array targets = {{"vs_5_0", "ps_5_0", "cs_5_0"}}; diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp index 9fe5d971e6..d01cf64c59 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp @@ -15,6 +15,7 @@ #include "common/StringUtil.h" #include "imgui.h" +#include "IconsFontAwesome5.h" #include #include @@ -94,8 +95,10 @@ bool GSDevice11::Create() wil::com_ptr_nothrow dxgi_adapter = D3D::GetAdapterByName(m_dxgi_factory.get(), GSConfig.Adapter); - static constexpr std::array requested_feature_levels = { - {D3D_FEATURE_LEVEL_11_0}}; + static constexpr std::array requested_feature_levels = {{ + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_0, + }}; wil::com_ptr_nothrow temp_dev; wil::com_ptr_nothrow temp_ctx; @@ -103,13 +106,13 @@ bool GSDevice11::Create() HRESULT hr = D3D11CreateDevice(dxgi_adapter.get(), dxgi_adapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE, nullptr, create_flags, requested_feature_levels.data(), static_cast(requested_feature_levels.size()), - D3D11_SDK_VERSION, temp_dev.put(), nullptr, temp_ctx.put()); + D3D11_SDK_VERSION, temp_dev.put(), &m_feature_level, temp_ctx.put()); if (FAILED(hr) || !temp_dev.try_query_to(&m_dev) || !temp_ctx.try_query_to(&m_ctx)) { Host::ReportErrorAsync("GS", fmt::format( - "Failed to create D3D device: 0x{:08X}. A GPU which supports Direct3D Feature Level 11.0 is required.", + "Failed to create D3D device: 0x{:08X}. A GPU which supports Direct3D Feature Level 10.0 is required.", hr)); return false; } @@ -165,7 +168,7 @@ bool GSDevice11::Create() if (GSConfig.UseDebugDevice) m_annotation = m_ctx.try_query(); - if (!m_shader_cache.Open(m_dev->GetFeatureLevel(), GSConfig.UseDebugDevice)) + if (!m_shader_cache.Open(m_feature_level, GSConfig.UseDebugDevice)) Console.Warning("Shader cache failed to open."); { @@ -496,12 +499,20 @@ bool GSDevice11::Create() return false; } - if (!CreateCASShaders()) + if (m_features.cas_sharpening && !CreateCASShaders()) return false; if (!CreateImGuiResources()) return false; + if (m_feature_level < D3D_FEATURE_LEVEL_11_0) + { + Host::AddIconOSDMessage("d3d11_feature_level_warning", ICON_FA_EXCLAMATION_TRIANGLE, + TRANSLATE_SV("GS", "The Direct3D renderer is running at feature level 10.0. This is an UNSUPPORTED configuration.\n" + "Do not request support, please upgrade your hardware/drivers first."), + Host::OSD_WARNING_DURATION); + } + return true; } @@ -568,8 +579,8 @@ void GSDevice11::SetFeatures(IDXGIAdapter1* adapter) m_features.bptc_textures = SupportsTextureFormat(m_dev.get(), DXGI_FORMAT_BC7_UNORM); - const D3D_FEATURE_LEVEL feature_level = m_dev->GetFeatureLevel(); - m_features.vs_expand = (!GSConfig.DisableVertexShaderExpand && feature_level >= D3D_FEATURE_LEVEL_11_0); + m_features.vs_expand = (!GSConfig.DisableVertexShaderExpand && m_feature_level >= D3D_FEATURE_LEVEL_11_0); + m_features.cas_sharpening = (m_feature_level >= D3D_FEATURE_LEVEL_11_0); // NVIDIA GPUs prior to Kepler appear to have broken vertex shader buffer loading. if (m_features.vs_expand && (D3D::GetVendorID(adapter) == D3D::VendorID::Nvidia)) @@ -586,6 +597,13 @@ void GSDevice11::SetFeatures(IDXGIAdapter1* adapter) } } +int GSDevice11::GetMaxTextureSize() const +{ + return (m_feature_level >= D3D_FEATURE_LEVEL_11_0) ? + D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION : + D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; +} + bool GSDevice11::HasSurface() const { return static_cast(m_swap_chain); @@ -823,15 +841,14 @@ std::string GSDevice11::GetDriverInfo() const { std::string ret = "Unknown Feature Level"; - static constexpr std::array, 4> feature_level_names = {{ + static constexpr std::array, 2> feature_level_names = {{ + {D3D_FEATURE_LEVEL_10_0, "D3D_FEATURE_LEVEL_10_0"}, {D3D_FEATURE_LEVEL_11_0, "D3D_FEATURE_LEVEL_11_0"}, - {D3D_FEATURE_LEVEL_11_1, "D3D_FEATURE_LEVEL_11_1"}, }}; - const D3D_FEATURE_LEVEL fl = m_dev->GetFeatureLevel(); for (size_t i = 0; i < std::size(feature_level_names); i++) { - if (fl == std::get<0>(feature_level_names[i])) + if (m_feature_level == std::get<0>(feature_level_names[i])) { ret = std::get<1>(feature_level_names[i]); break; @@ -1155,8 +1172,8 @@ GSTexture* GSDevice11::CreateSurface(GSTexture::Type type, int width, int height D3D11_TEXTURE2D_DESC desc = {}; // Texture limit for D3D10/11 min 1, max 8192 D3D10, max 16384 D3D11. - desc.Width = std::clamp(width, 1, D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION); - desc.Height = std::clamp(height, 1, D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION); + desc.Width = std::clamp(width, 1, GetMaxTextureSize()); + desc.Height = std::clamp(height, 1, GetMaxTextureSize()); desc.Format = GSTexture11::GetDXGIFormat(format); desc.MipLevels = levels; desc.ArraySize = 1; @@ -1586,7 +1603,7 @@ void GSDevice11::DoFXAA(GSTexture* sTex, GSTexture* dTex) } ShaderMacro sm; - sm.AddMacro("FXAA_HLSL_5", "1"); + sm.AddMacro("FXAA_HLSL", "1"); m_fxaa_ps = m_shader_cache.GetPixelShader(m_dev.get(), *shader, sm.GetPtr(), "main"); if (!m_fxaa_ps) return; diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.h b/pcsx2/GS/Renderers/DX11/GSDevice11.h index 02f766aac3..8a7777a3c2 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.h +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.h @@ -91,6 +91,7 @@ private: }; void SetFeatures(IDXGIAdapter1* adapter); + int GetMaxTextureSize() const; bool CreateSwapChain(); bool CreateSwapChainRTV(); @@ -125,6 +126,8 @@ private: wil::com_ptr_nothrow m_expand_vb; wil::com_ptr_nothrow m_expand_ib; wil::com_ptr_nothrow m_expand_vb_srv; + + D3D_FEATURE_LEVEL m_feature_level = D3D_FEATURE_LEVEL_10_0; u32 m_vb_pos = 0; // bytes u32 m_ib_pos = 0; // indices/sizeof(u32) u32 m_structured_vb_pos = 0; // bytes @@ -136,8 +139,8 @@ private: struct { - ID3D11InputLayout* layout; D3D11_PRIMITIVE_TOPOLOGY topology; + ID3D11InputLayout* layout; ID3D11Buffer* index_buffer; ID3D11VertexShader* vs; ID3D11Buffer* vs_cb;