Skip to content

Commit

Permalink
Merge pull request #8047 from stenzek/d3d-feature-level-10
Browse files Browse the repository at this point in the history
D3D11: Fix Dolphin crashing on feature level 10.0 devices
  • Loading branch information
stenzek committed Apr 28, 2019
2 parents 96c69fd + 025767c commit f719939
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
44 changes: 10 additions & 34 deletions Source/Core/VideoBackends/D3D/D3DBase.cpp
Expand Up @@ -33,29 +33,6 @@ static ComPtr<ID3D11Debug> s_debug;
static constexpr D3D_FEATURE_LEVEL s_supported_feature_levels[] = { static constexpr D3D_FEATURE_LEVEL s_supported_feature_levels[] = {
D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0}; 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) bool Create(u32 adapter_index, bool enable_debug_layer)
{ {
PFN_D3D11_CREATE_DEVICE d3d11_create_device; PFN_D3D11_CREATE_DEVICE d3d11_create_device;
Expand Down Expand Up @@ -145,17 +122,6 @@ bool Create(u32 adapter_index, bool enable_debug_layer)
g_Config.backend_info.bSupportsLogicOp = false; 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<StateManager>(); stateman = std::make_unique<StateManager>();
return true; return true;
} }
Expand Down Expand Up @@ -241,6 +207,16 @@ std::vector<u32> GetAAModes(u32 adapter_index)


return aa_modes; 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 D3D


} // namespace DX11 } // namespace DX11
3 changes: 3 additions & 0 deletions Source/Core/VideoBackends/D3D/D3DBase.h
Expand Up @@ -40,6 +40,9 @@ void Destroy();
// Returns a list of supported AA modes for the current device. // Returns a list of supported AA modes for the current device.
std::vector<u32> GetAAModes(u32 adapter_index); std::vector<u32> GetAAModes(u32 adapter_index);


// Checks for support of the given texture format.
bool SupportsTextureFormat(DXGI_FORMAT format);

} // namespace D3D } // namespace D3D


} // namespace DX11 } // namespace DX11
19 changes: 19 additions & 0 deletions Source/Core/VideoBackends/D3D/main.cpp
Expand Up @@ -87,6 +87,25 @@ void VideoBackend::FillBackendInfo()


g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames(); g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
g_Config.backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter); 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) bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
Expand Down
11 changes: 7 additions & 4 deletions Source/Core/VideoCommon/FramebufferShaderGen.cpp
Expand Up @@ -410,10 +410,13 @@ std::string GenerateFormatConversionShader(EFBReinterpretType convtype, u32 samp
{ {
std::stringstream ss; std::stringstream ss;
EmitSamplerDeclarations(ss, 0, 1, samples > 1); EmitSamplerDeclarations(ss, 0, 1, samples > 1);
EmitPixelMainDeclaration(ss, 1, 0, "float4", EmitPixelMainDeclaration(
GetAPIType() == APIType::D3D ? ss, 1, 0, "float4",
"in float4 ipos : SV_Position, in uint isample : SV_SampleIndex, " : GetAPIType() == APIType::D3D ?
""); (g_ActiveConfig.bSSAA ?
"in float4 ipos : SV_Position, in uint isample : SV_SampleIndex, " :
"in float4 ipos : SV_Position, ") :
"");
ss << "{\n"; ss << "{\n";
ss << " int layer = int(v_tex0.z);\n"; ss << " int layer = int(v_tex0.z);\n";
if (GetAPIType() == APIType::D3D) if (GetAPIType() == APIType::D3D)
Expand Down

0 comments on commit f719939

Please sign in to comment.