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; ID3D12Device *d3dDevice = NULL;
HRESULT result = S_OK; HRESULT result = S_OK;
UINT creationFlags = 0; UINT creationFlags = 0;
int i, j, k, l; int i;
SDL_bool createDebug; SDL_bool createDebug;
D3D12_COMMAND_QUEUE_DESC queueDesc; D3D12_COMMAND_QUEUE_DESC queueDesc;
@@ -757,21 +757,6 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
D3D12_SAMPLER_DESC samplerDesc; D3D12_SAMPLER_DESC samplerDesc;
ID3D12DescriptorHeap *rootDescriptorHeaps[2]; 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 */ /* See if we need debug interfaces */
createDebug = SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE); createDebug = SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE);
@@ -1056,20 +1041,40 @@ static HRESULT D3D12_CreateDeviceResources(SDL_Renderer *renderer)
} }
} }
/* Create all the default pipeline state objects #if 0 /* Actually, don't do this, it causes a huge startup time on some systems */
(will add everything except custom blend states) */ {
for (i = 0; i < NUM_SHADERS; ++i) { const SDL_BlendMode defaultBlendModes[] = {
for (j = 0; j < SDL_arraysize(defaultBlendModes); ++j) { SDL_BLENDMODE_NONE,
for (k = D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT; k < D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH; ++k) { SDL_BLENDMODE_BLEND,
for (l = 0; l < SDL_arraysize(defaultRTVFormats); ++l) { SDL_BLENDMODE_ADD,
if (!D3D12_CreatePipelineState(renderer, (D3D12_Shader)i, defaultBlendModes[j], (D3D12_PRIMITIVE_TOPOLOGY_TYPE)k, defaultRTVFormats[l])) { SDL_BLENDMODE_MOD,
/* D3D12_CreatePipelineState will set the SDL error, if it fails */ SDL_BLENDMODE_MUL
goto done; };
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) {
for (j = 0; j < SDL_arraysize(defaultBlendModes); ++j) {
for (k = D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT; k < D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH; ++k) {
for (l = 0; l < SDL_arraysize(defaultRTVFormats); ++l) {
if (!D3D12_CreatePipelineState(renderer, (D3D12_Shader)i, defaultBlendModes[j], (D3D12_PRIMITIVE_TOPOLOGY_TYPE)k, defaultRTVFormats[l])) {
/* D3D12_CreatePipelineState will set the SDL error, if it fails */
goto done;
}
} }
} }
} }
} }
} }
#endif /* 0 */
/* Create default vertex buffers */ /* Create default vertex buffers */
for (i = 0; i < SDL_D3D12_NUM_VERTEX_BUFFERS; ++i) { for (i = 0; i < SDL_D3D12_NUM_VERTEX_BUFFERS; ++i) {