From 2deceaa0aff4ea5e44896a163a28286795900e8d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 12 Nov 2022 00:20:15 +0900 Subject: [PATCH] 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 --- internal/graphicsdriver/directx/api_windows.go | 2 +- internal/graphicsdriver/directx/graphics_windows.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/graphicsdriver/directx/api_windows.go b/internal/graphicsdriver/directx/api_windows.go index 38dc16ce78e..aee9deccf3c 100644 --- a/internal/graphicsdriver/directx/api_windows.go +++ b/internal/graphicsdriver/directx/api_windows.go @@ -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 diff --git a/internal/graphicsdriver/directx/graphics_windows.go b/internal/graphicsdriver/directx/graphics_windows.go index 8a2f2bc858c..360f7cd2411 100644 --- a/internal/graphicsdriver/directx/graphics_windows.go +++ b/internal/graphicsdriver/directx/graphics_windows.go @@ -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 }