Skip to content
Permalink
Browse files

D3D: Set optional features after creating the device

Fixes feature level 10.0 devices crashing during runtime.
  • Loading branch information...
stenzek committed Apr 28, 2019
1 parent 51154d6 commit 025767c9293a8ecf770daef063005491898206f6
@@ -33,29 +33,6 @@ static ComPtr<ID3D11Debug> 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<StateManager>();
return true;
}
@@ -241,6 +207,16 @@ std::vector<u32> 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
@@ -40,6 +40,9 @@ void Destroy();
// Returns a list of supported AA modes for the current device.
std::vector<u32> GetAAModes(u32 adapter_index);

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

} // namespace D3D

} // namespace DX11
@@ -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)

0 comments on commit 025767c

Please sign in to comment.
You can’t perform that action at this time.