Fix threading issues with GPU buffers mapping

This commit is contained in:
Wojciech Figat
2023-01-04 12:06:56 +01:00
parent 0b8d4850f0
commit 88bd5b2534
6 changed files with 15 additions and 6 deletions

View File

@@ -21,6 +21,7 @@ void* GPUBufferDX11::Map(GPUResourceMapMode mode)
{
if (!IsInMainThread())
_device->Locker.Lock();
ASSERT(!_mapped);
D3D11_MAPPED_SUBRESOURCE map;
map.pData = nullptr;
@@ -46,13 +47,18 @@ void* GPUBufferDX11::Map(GPUResourceMapMode mode)
const HRESULT result = _device->GetIM()->Map(_resource, 0, mapType, mapFlags, &map);
if (result != DXGI_ERROR_WAS_STILL_DRAWING)
LOG_DIRECTX_RESULT(result);
_mapped = map.pData != nullptr;
return map.pData;
}
void GPUBufferDX11::Unmap()
{
_device->GetIM()->Unmap(_resource, 0);
if (_mapped)
{
_mapped = false;
_device->GetIM()->Unmap(_resource, 0);
}
if (!IsInMainThread())
_device->Locker.Unlock();
}

View File

@@ -101,6 +101,7 @@ private:
ID3D11Buffer* _resource = nullptr;
GPUBufferViewDX11 _view;
bool _mapped = false;
public: