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

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

View File

@ -1780,14 +1780,24 @@ func (i *_ID3D12Resource) GetGPUVirtualAddress() _D3D12_GPU_VIRTUAL_ADDRESS {
return _D3D12_GPU_VIRTUAL_ADDRESS(r) return _D3D12_GPU_VIRTUAL_ADDRESS(r)
} }
func (i *_ID3D12Resource) Map(subresource uint32, pReadRange *_D3D12_RANGE) (unsafe.Pointer, error) { func (i *_ID3D12Resource) Map(subresource uint32, pReadRange *_D3D12_RANGE) (uintptr, error) {
var data unsafe.Pointer var retryCount int
retry:
var data uintptr
r, _, _ := syscall.Syscall6(i.vtbl.Map, 4, uintptr(unsafe.Pointer(i)), r, _, _ := syscall.Syscall6(i.vtbl.Map, 4, uintptr(unsafe.Pointer(i)),
uintptr(subresource), uintptr(unsafe.Pointer(pReadRange)), uintptr(unsafe.Pointer(&data)), uintptr(subresource), uintptr(unsafe.Pointer(pReadRange)), uintptr(unsafe.Pointer(&data)),
0, 0) 0, 0)
runtime.KeepAlive(pReadRange) runtime.KeepAlive(pReadRange)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Resource::Map failed: HRESULT(%d)", uint32(r)) return 0, fmt.Errorf("directx: ID3D12Resource::Map failed: HRESULT(%d)", uint32(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 return data, nil
} }

View File

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