internal/graphicsdriver/directx: specify DX level 12

The DirectX initialization passed but crashed later on some old machines
supporting the feature level 11 but not 12.

This change fixes the issue by changing the required feature level from
11 to 12 so that the initialization fails and OpenGL is used as the
fallback.

Closes #2447
This commit is contained in:
Hajime Hoshi 2022-11-12 00:20:15 +09:00
parent f885c0db43
commit 2deceaa0af
2 changed files with 6 additions and 3 deletions

View File

@ -73,7 +73,7 @@ const (
type _D3D_FEATURE_LEVEL int32
const (
_D3D_FEATURE_LEVEL_11_0 _D3D_FEATURE_LEVEL = 0xb000
_D3D_FEATURE_LEVEL_12_0 _D3D_FEATURE_LEVEL = 0xc000
)
type _D3D_PRIMITIVE_TOPOLOGY int32

View File

@ -185,6 +185,7 @@ func (g *Graphics) initialize() (ferr error) {
return err
}
}
return nil
}
@ -256,7 +257,9 @@ func (g *Graphics) initializeDesktop(useWARP bool, useDebugLayer bool) (ferr err
continue
}
// Test D3D12CreateDevice without creating an actual device.
if _, err := _D3D12CreateDevice(unsafe.Pointer(adapter), _D3D_FEATURE_LEVEL_11_0, &_IID_ID3D12Device, false); err != nil {
// Ebitengine itself doesn't require the features level 12 and 11 should be enough,
// but some old cards don't work well (#2447). Specify the level 12 here.
if _, err := _D3D12CreateDevice(unsafe.Pointer(adapter), _D3D_FEATURE_LEVEL_12_0, &_IID_ID3D12Device, false); err != nil {
continue
}
break
@ -267,7 +270,7 @@ func (g *Graphics) initializeDesktop(useWARP bool, useDebugLayer bool) (ferr err
return errors.New("directx: DirectX 12 is not supported")
}
d, err := _D3D12CreateDevice(unsafe.Pointer(adapter), _D3D_FEATURE_LEVEL_11_0, &_IID_ID3D12Device, true)
d, err := _D3D12CreateDevice(unsafe.Pointer(adapter), _D3D_FEATURE_LEVEL_12_0, &_IID_ID3D12Device, true)
if err != nil {
return err
}