Skip to content

Commit

Permalink
GS: Use DX11/GL for Auto when no compatible Vulkan devices exist
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 29, 2023
1 parent 5f51050 commit fe2ed74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 26 additions & 3 deletions pcsx2/GS/Renderers/DX11/D3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
#include "GS/Renderers/Common/GSDevice.h"
#include "GS/Renderers/DX11/D3D.h"
#include "GS/GSExtra.h"
#include "Host.h"

#ifdef _M_X86
#include "GS/Renderers/Vulkan/GSDeviceVK.h"
#endif

#include "common/Console.h"
#include "common/StringUtil.h"
#include "common/Path.h"

#include "IconsFontAwesome5.h"

#include <array>
#include <d3d11.h>
#include <d3d12.h>
Expand Down Expand Up @@ -310,6 +317,8 @@ std::string D3D::GetDriverVersionFromLUID(const LUID& luid)
return ret;
}

#ifdef _M_X86

D3D::VendorID D3D::GetVendorID(IDXGIAdapter1* adapter)
{
DXGI_ADAPTER_DESC1 desc;
Expand Down Expand Up @@ -371,6 +380,18 @@ GSRendererType D3D::GetPreferredRenderer()
Console.Error("D3D12CreateDevice() for automatic renderer failed: %08X", hr);
return device;
};
const auto check_vulkan_supported = []() {
std::vector<std::string> vk_adapter_names;
GSDeviceVK::GetAdaptersAndFullscreenModes(&vk_adapter_names, nullptr);
if (!vk_adapter_names.empty())
return true;

Host::AddIconOSDMessage("VKDriverUnsupported", ICON_FA_TV, TRANSLATE_STR("GS",
"The Vulkan renderer was automatically selected, but no compatible devices were found.\n"
" You should update all graphics drivers in your system, including any integrated GPUs\n"
" to use the Vulkan renderer."), Host::OSD_WARNING_DURATION);
return false;
};

switch (GetVendorID(adapter.get()))
{
Expand All @@ -380,7 +401,7 @@ GSRendererType D3D::GetPreferredRenderer()
if (!feature_level.has_value())
return GSRendererType::DX11;
else if (feature_level == D3D_FEATURE_LEVEL_12_0)
return GSRendererType::VK;
return check_vulkan_supported() ? GSRendererType::VK : GSRendererType::OGL;
else if (feature_level == D3D_FEATURE_LEVEL_11_0)
return GSRendererType::OGL;
else
Expand All @@ -393,7 +414,7 @@ GSRendererType D3D::GetPreferredRenderer()
if (!feature_level.has_value())
return GSRendererType::DX11;
else if (feature_level == D3D_FEATURE_LEVEL_12_0)
return GSRendererType::VK;
return check_vulkan_supported() ? GSRendererType::VK : GSRendererType::DX11;
else
return GSRendererType::DX11;
}
Expand All @@ -414,7 +435,7 @@ GSRendererType D3D::GetPreferredRenderer()
opts.SamplerFeedbackTier >= D3D12_SAMPLER_FEEDBACK_TIER_0_9)
{
Console.WriteLn("Sampler feedback tier 0.9 found for Intel GPU, defaulting to Vulkan.");
return GSRendererType::VK;
return check_vulkan_supported() ? GSRendererType::VK : GSRendererType::DX11;
}
}

Expand All @@ -431,6 +452,8 @@ GSRendererType D3D::GetPreferredRenderer()
}
}

#endif // _M_X86

wil::com_ptr_nothrow<ID3DBlob> D3D::CompileShader(D3D::ShaderType type, D3D_FEATURE_LEVEL feature_level, bool debug,
const std::string_view& code, const D3D_SHADER_MACRO* macros /* = nullptr */,
const char* entry_point /* = "main" */)
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/GS/Renderers/DX11/D3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace D3D
// returns the driver version from the registry as a string
std::string GetDriverVersionFromLUID(const LUID& luid);

#ifdef _M_X86
// this is sort of a legacy thing that doesn't have much to do with d3d (just the easiest way)
// checks to see if the adapter at 0 is NV and thus we should prefer OpenGL
enum class VendorID
Expand All @@ -56,6 +57,7 @@ namespace D3D

VendorID GetVendorID(IDXGIAdapter1* adapter);
GSRendererType GetPreferredRenderer();
#endif

// D3DCompiler wrapper.
enum class ShaderType
Expand Down

0 comments on commit fe2ed74

Please sign in to comment.