Fixed slow startup time when using the direct3d12 renderer

On some systems creating the entire set of available pipeline states is very time consuming. We'll only use a few of them in any given program, so we'll just create them on demand.

Fixes https://github.com/libsdl-org/SDL/issues/7634
This commit is contained in:
Sam Lantinga
2024-02-04 12:08:55 -08:00
parent dab77fe29b
commit 548b382fd9

View File

@@ -749,7 +749,7 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
ID3D12Device *d3dDevice = NULL;
HRESULT result = S_OK;
UINT creationFlags = 0;
int i, j, k, l;
int i;
SDL_bool createDebug;
D3D12_COMMAND_QUEUE_DESC queueDesc;
@@ -757,21 +757,6 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
D3D12_SAMPLER_DESC samplerDesc;
ID3D12DescriptorHeap *rootDescriptorHeaps[2];
const SDL_BlendMode defaultBlendModes[] = {
SDL_BLENDMODE_NONE,
SDL_BLENDMODE_BLEND,
SDL_BLENDMODE_ADD,
SDL_BLENDMODE_MOD,
SDL_BLENDMODE_MUL
};
const DXGI_FORMAT defaultRTVFormats[] = {
DXGI_FORMAT_R16G16B16A16_FLOAT,
DXGI_FORMAT_R10G10B10A2_UNORM,
DXGI_FORMAT_B8G8R8A8_UNORM,
DXGI_FORMAT_B8G8R8X8_UNORM,
DXGI_FORMAT_R8_UNORM
};
/* See if we need debug interfaces */
createDebug = SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE);
@@ -1056,6 +1041,24 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
}
}
#if 0 /* Actually, don't do this, it causes a huge startup time on some systems */
{
const SDL_BlendMode defaultBlendModes[] = {
SDL_BLENDMODE_NONE,
SDL_BLENDMODE_BLEND,
SDL_BLENDMODE_ADD,
SDL_BLENDMODE_MOD,
SDL_BLENDMODE_MUL
};
const DXGI_FORMAT defaultRTVFormats[] = {
DXGI_FORMAT_R16G16B16A16_FLOAT,
DXGI_FORMAT_R10G10B10A2_UNORM,
DXGI_FORMAT_B8G8R8A8_UNORM,
DXGI_FORMAT_B8G8R8X8_UNORM,
DXGI_FORMAT_R8_UNORM
};
int i, j, k, l;
/* Create all the default pipeline state objects
(will add everything except custom blend states) */
for (i = 0; i < NUM_SHADERS; ++i) {
@@ -1070,6 +1073,8 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
}
}
}
}
#endif /* 0 */
/* Create default vertex buffers */
for (i = 0; i < SDL_D3D12_NUM_VERTEX_BUFFERS; ++i) {