GS/DX11: Re-enable FL10 support with a warning

This commit is contained in:
Stenzek 2024-03-30 02:21:13 +10:00 committed by Connor McLaughlin
parent 4dca6c3bb2
commit 299fd3d5ad
4 changed files with 51 additions and 27 deletions

View File

@ -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<float>
#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<float> 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;

View File

@ -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<ID3DBlob> D3D::CompileShader(D3D::ShaderType type, D3D_FEAT
const char* target;
switch (feature_level)
{
case D3D_FEATURE_LEVEL_10_0:
{
static constexpr std::array<const char*, 4> targets = {{"vs_4_0", "ps_4_0", "cs_4_0"}};
target = targets[static_cast<int>(type)];
}
break;
case D3D_FEATURE_LEVEL_11_0:
{
static constexpr std::array<const char*, 4> targets = {{"vs_5_0", "ps_5_0", "cs_5_0"}};

View File

@ -15,6 +15,7 @@
#include "common/StringUtil.h"
#include "imgui.h"
#include "IconsFontAwesome5.h"
#include <bit>
#include <fstream>
@ -94,8 +95,10 @@ bool GSDevice11::Create()
wil::com_ptr_nothrow<IDXGIAdapter1> dxgi_adapter = D3D::GetAdapterByName(m_dxgi_factory.get(), GSConfig.Adapter);
static constexpr std::array<D3D_FEATURE_LEVEL, 1> requested_feature_levels = {
{D3D_FEATURE_LEVEL_11_0}};
static constexpr std::array<D3D_FEATURE_LEVEL, 2> requested_feature_levels = {{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_0,
}};
wil::com_ptr_nothrow<ID3D11Device> temp_dev;
wil::com_ptr_nothrow<ID3D11DeviceContext> 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<UINT>(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<ID3DUserDefinedAnnotation>();
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<bool>(m_swap_chain);
@ -823,15 +841,14 @@ std::string GSDevice11::GetDriverInfo() const
{
std::string ret = "Unknown Feature Level";
static constexpr std::array<std::tuple<D3D_FEATURE_LEVEL, const char*>, 4> feature_level_names = {{
static constexpr std::array<std::tuple<D3D_FEATURE_LEVEL, const char*>, 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;

View File

@ -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<ID3D11Buffer> m_expand_vb;
wil::com_ptr_nothrow<ID3D11Buffer> m_expand_ib;
wil::com_ptr_nothrow<ID3D11ShaderResourceView> 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;