mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 15:47:31 +08:00
gpu: Set up D3D12 device checks to avoid unnecessary queries
This commit is contained in:
@@ -8374,6 +8374,7 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
|
|||||||
IDXGIFactory6 *factory6;
|
IDXGIFactory6 *factory6;
|
||||||
IDXGIAdapter1 *adapter;
|
IDXGIAdapter1 *adapter;
|
||||||
bool supports_64UAVs = false;
|
bool supports_64UAVs = false;
|
||||||
|
bool needs_64UAVs = !SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_D3D12_ALLOW_FEWER_RESOURCE_SLOTS_BOOLEAN, false);
|
||||||
|
|
||||||
// Early check to see if the app has _any_ D3D12 formats, if not we don't
|
// Early check to see if the app has _any_ D3D12 formats, if not we don't
|
||||||
// have to fuss with loading D3D in the first place.
|
// have to fuss with loading D3D in the first place.
|
||||||
@@ -8475,23 +8476,29 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
|
|||||||
|
|
||||||
SDL_COMPILE_TIME_ASSERT(featurelevel, D3D_FEATURE_LEVEL_CHOICE < D3D_FEATURE_LEVEL_11_1);
|
SDL_COMPILE_TIME_ASSERT(featurelevel, D3D_FEATURE_LEVEL_CHOICE < D3D_FEATURE_LEVEL_11_1);
|
||||||
|
|
||||||
// Check feature level 11_1 first, guarantees 64+ UAVs unlike 11_0 Tier1
|
/* FIXME: If Windows 11 is running and the app has neither DXIL nor TIER2
|
||||||
|
* requirements, we can skip doing any device checks entirely
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
if (!needs_64UAVs && !has_dxil && WIN_IsWindows11OrGreater()) {
|
||||||
|
IDXGIAdapter1_Release(adapter);
|
||||||
|
IDXGIFactory1_Release(factory);
|
||||||
|
|
||||||
|
SDL_UnloadObject(d3d12Dll);
|
||||||
|
SDL_UnloadObject(dxgiDll);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
res = pD3D12CreateDevice(
|
res = pD3D12CreateDevice(
|
||||||
(IUnknown *)adapter,
|
(IUnknown *)adapter,
|
||||||
D3D_FEATURE_LEVEL_11_1,
|
D3D_FEATURE_LEVEL_CHOICE,
|
||||||
D3D_GUID(D3D_IID_ID3D12Device),
|
D3D_GUID(D3D_IID_ID3D12Device),
|
||||||
(void **)&device);
|
(void **)&device);
|
||||||
|
|
||||||
if (SUCCEEDED(res)) {
|
if (SUCCEEDED(res)) {
|
||||||
supports_64UAVs = true;
|
// Only check for Tier 2 resource binding if the app needs it
|
||||||
} else {
|
if (needs_64UAVs) {
|
||||||
res = pD3D12CreateDevice(
|
|
||||||
(IUnknown *)adapter,
|
|
||||||
D3D_FEATURE_LEVEL_CHOICE,
|
|
||||||
D3D_GUID(D3D_IID_ID3D12Device),
|
|
||||||
(void **)&device);
|
|
||||||
|
|
||||||
if (SUCCEEDED(res)) {
|
|
||||||
D3D12_FEATURE_DATA_D3D12_OPTIONS featureOptions;
|
D3D12_FEATURE_DATA_D3D12_OPTIONS featureOptions;
|
||||||
SDL_zero(featureOptions);
|
SDL_zero(featureOptions);
|
||||||
|
|
||||||
@@ -8504,30 +8511,32 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this, SDL_PropertiesID props)
|
|||||||
supports_64UAVs = true;
|
supports_64UAVs = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (SUCCEEDED(res)) {
|
// Only check for SM6 support if DXIL is provided
|
||||||
D3D12_FEATURE_DATA_SHADER_MODEL shaderModel;
|
if (has_dxil) {
|
||||||
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_0;
|
D3D12_FEATURE_DATA_SHADER_MODEL shaderModel;
|
||||||
|
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_0;
|
||||||
|
|
||||||
res = ID3D12Device_CheckFeatureSupport(
|
res = ID3D12Device_CheckFeatureSupport(
|
||||||
device,
|
device,
|
||||||
D3D12_FEATURE_SHADER_MODEL,
|
D3D12_FEATURE_SHADER_MODEL,
|
||||||
&shaderModel,
|
&shaderModel,
|
||||||
sizeof(shaderModel));
|
sizeof(shaderModel));
|
||||||
if (SUCCEEDED(res) && shaderModel.HighestShaderModel >= D3D_SHADER_MODEL_6_0) {
|
if (SUCCEEDED(res) && shaderModel.HighestShaderModel >= D3D_SHADER_MODEL_6_0) {
|
||||||
supports_dxil = true;
|
supports_dxil = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D12Device_Release(device);
|
ID3D12Device_Release(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDXGIAdapter1_Release(adapter);
|
IDXGIAdapter1_Release(adapter);
|
||||||
IDXGIFactory1_Release(factory);
|
IDXGIFactory1_Release(factory);
|
||||||
|
|
||||||
SDL_UnloadObject(d3d12Dll);
|
SDL_UnloadObject(d3d12Dll);
|
||||||
SDL_UnloadObject(dxgiDll);
|
SDL_UnloadObject(dxgiDll);
|
||||||
|
|
||||||
if (!supports_64UAVs && !SDL_GetBooleanProperty(props, SDL_PROP_GPU_DEVICE_CREATE_D3D12_ALLOW_FEWER_RESOURCE_SLOTS_BOOLEAN, false)) {
|
if (!supports_64UAVs && needs_64UAVs) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D12: Tier 2 Resource Binding is not supported");
|
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "D3D12: Tier 2 Resource Binding is not supported");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user