internal/graphicsdriver/directx: bug fix: ID3D12Resource::Map sometimes needs retrying

Updates #2113
Closes #2116
This commit is contained in:
Hajime Hoshi 2022-06-03 21:46:31 +09:00
parent dbb8067761
commit a9afacc8c6
2 changed files with 17 additions and 7 deletions

View File

@ -1727,14 +1727,24 @@ func (i *iD3D12Resource1) GetGPUVirtualAddress() _D3D12_GPU_VIRTUAL_ADDRESS {
return _D3D12_GPU_VIRTUAL_ADDRESS(r)
}
func (i *iD3D12Resource1) Map(subresource uint32, pReadRange *_D3D12_RANGE) (unsafe.Pointer, error) {
var data unsafe.Pointer
func (i *iD3D12Resource1) Map(subresource uint32, pReadRange *_D3D12_RANGE) (uintptr, error) {
var retryCount int
retry:
var data uintptr
r, _, _ := syscall.Syscall6(i.vtbl.Map, 4, uintptr(unsafe.Pointer(i)),
uintptr(subresource), uintptr(unsafe.Pointer(pReadRange)), uintptr(unsafe.Pointer(&data)),
0, 0)
runtime.KeepAlive(pReadRange)
if windows.Handle(r) != windows.S_OK {
return nil, fmt.Errorf("directx: ID3D12Resource1::Map failed: %w", windows.Errno(r))
return 0, fmt.Errorf("directx: ID3D12Resource1::Map failed: %w", windows.Errno(r))
}
if data == 0 {
// This is very mysterious, but sometimes Map fails especially on tests with Warp and/or Proton (Steam Deck) (#2113).
if retryCount >= 5 {
return 0, fmt.Errorf("directx: ID3D12Resource::Map failed: nothing is mapped")
}
retryCount++
goto retry
}
return data, nil
}

View File

@ -1531,19 +1531,19 @@ func (i *Image) ensureDepthStencilView(device *iD3D12Device) error {
return nil
}
func copyFloat32s(dst unsafe.Pointer, src []float32) {
func copyFloat32s(dst uintptr, src []float32) {
var dsts []float32
h := (*reflect.SliceHeader)(unsafe.Pointer(&dsts))
h.Data = uintptr(dst)
h.Data = dst
h.Len = len(src)
h.Cap = len(src)
copy(dsts, src)
}
func copyUint16s(dst unsafe.Pointer, src []uint16) {
func copyUint16s(dst uintptr, src []uint16) {
var dsts []uint16
h := (*reflect.SliceHeader)(unsafe.Pointer(&dsts))
h.Data = uintptr(dst)
h.Data = dst
h.Len = len(src)
h.Cap = len(src)
copy(dsts, src)