internal/graphicsdriver/directx: refactoring

Updates #2084
This commit is contained in:
Hajime Hoshi 2022-05-30 03:17:13 +09:00
parent d4226659ee
commit c99b948df3
4 changed files with 21 additions and 19 deletions

View File

@ -19,11 +19,12 @@ import (
"math"
"reflect"
"runtime"
"sync"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
)
type (
@ -875,29 +876,15 @@ type _D3D12XBOX_CREATE_DEVICE_PARAMETERS struct {
var (
d3d12 = windows.NewLazySystemDLL("d3d12.dll")
d3d12x = windows.NewLazySystemDLL(microsoftgdk.D3D12DLLName())
d3dcompiler = windows.NewLazySystemDLL("d3dcompiler_47.dll")
dxgi = windows.NewLazySystemDLL("dxgi.dll")
d3d12xDLL *windows.LazyDLL
d3d12xOnce sync.Once
)
func d3d12x() *windows.LazyDLL {
d3d12xOnce.Do(func() {
d3d12xDLL = windows.NewLazySystemDLL("d3d12_xs.dll")
if d3d12xDLL.Load() != nil {
d3d12xDLL = windows.NewLazySystemDLL("d3d12_x.dll")
}
})
return d3d12xDLL
}
var (
procD3D12CreateDevice = d3d12.NewProc("D3D12CreateDevice")
procD3D12GetDebugInterface = d3d12.NewProc("D3D12GetDebugInterface")
procD3D12SerializeRootSignature = d3d12.NewProc("D3D12SerializeRootSignature")
procD3D12XboxCreateDevice = d3d12x().NewProc("D3D12XboxCreateDevice")
procD3D12XboxCreateDevice = d3d12x.NewProc("D3D12XboxCreateDevice")
procD3DCompile = d3dcompiler.NewProc("D3DCompile")

View File

@ -277,7 +277,7 @@ func (g *Graphics) initializeDeviceDesktop(useWARP bool, useDebugLayer bool) (fe
}
func (g *Graphics) initializeDeviceXbox(useWARP bool, useDebugLayer bool) (ferr error) {
if err := d3d12x().Load(); err != nil {
if err := d3d12x.Load(); err != nil {
return err
}

View File

@ -59,3 +59,14 @@ func MonitorResolution() (int, int) {
return 1920, 1080
}
}
func D3D12DLLName() string {
switch C.XSystemGetDeviceType() {
case _XSystemDeviceType_XboxOne, _XSystemDeviceType_XboxOneS, _XSystemDeviceType_XboxOneX, _XSystemDeviceType_XboxOneXDevkit:
return "d3d12_x.dll"
case _XSystemDeviceType_XboxScarlettLockhart, _XSystemDeviceType_XboxScarlettAnaconda, _XSystemDeviceType_XboxScarlettDevkit:
return "d3d12_xs.dll"
default:
return ""
}
}

View File

@ -22,5 +22,9 @@ func IsXbox() bool {
}
func MonitorResolution() (int, int) {
panic("microsoftgdk: MonitorResolution is not implemented in this environment")
return 0, 0
}
func D3D12DLLName() string {
return ""
}