From cd4f21a0c3d47d09775602100398942f08b4388d Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 10 Dec 2017 17:36:32 +0100 Subject: [PATCH] [d3d11] Implemented buffer mapping --- src/d3d11/d3d11_context.cpp | 39 ++++++++++++++++++++++++++++++++++--- src/d3d11/d3d11_device.cpp | 22 +++++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 95248cdef..afdba50c1 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -143,15 +143,48 @@ namespace dxvk { D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource) { - Logger::err("D3D11DeviceContext::Map: Not implemented"); - return E_NOTIMPL; + D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; + pResource->GetType(&resourceDim); + + if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) { + D3D11Buffer* resource = static_cast(pResource); + + const Rc buffer = resource->GetDXVKBuffer(); + + if (buffer->mapPtr(0) == nullptr) { + Logger::err("D3D11: Cannot map a device-local buffer"); + return E_FAIL; + } + + if (pMappedResource == nullptr) + return S_OK; + + if (buffer->isInUse()) { + if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT) + return DXGI_ERROR_WAS_STILL_DRAWING; + + this->Flush(); + m_device->waitForIdle(); + // TODO properly synchronize + } + + pMappedResource->pData = buffer->mapPtr(0); + pMappedResource->RowPitch = buffer->info().size; + pMappedResource->DepthPitch = buffer->info().size; + return E_FAIL; + } else { + Logger::err("D3D11: Mapping of image resources currently not supported"); + return E_NOTIMPL; + } } void D3D11DeviceContext::Unmap( ID3D11Resource* pResource, UINT Subresource) { - Logger::err("D3D11DeviceContext::Unmap: Not implemented"); + // There's literally nothing we have to do here at the moment + this->Flush(); + m_device->waitForIdle(); } diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index d53a934e4..855b9f254 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -114,6 +114,16 @@ namespace dxvk { | VK_ACCESS_SHADER_WRITE_BIT; } + if (pDesc->CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) { + info.stages |= VK_PIPELINE_STAGE_HOST_BIT; + info.access |= VK_ACCESS_HOST_WRITE_BIT; + } + + if (pDesc->CPUAccessFlags & D3D11_CPU_ACCESS_READ) { + info.stages |= VK_PIPELINE_STAGE_HOST_BIT; + info.access |= VK_ACCESS_HOST_READ_BIT; + } + if (pDesc->MiscFlags & D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS) { info.usage |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; info.stages |= VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT; @@ -205,8 +215,16 @@ namespace dxvk { | VK_ACCESS_SHADER_WRITE_BIT; } - if (pDesc->CPUAccessFlags != 0) - info.tiling = VK_IMAGE_TILING_LINEAR; + if (pDesc->CPUAccessFlags != 0) { + info.tiling = VK_IMAGE_TILING_LINEAR; + info.stages |= VK_PIPELINE_STAGE_HOST_BIT; + + if (pDesc->CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) + info.access |= VK_ACCESS_HOST_WRITE_BIT; + + if (pDesc->CPUAccessFlags & D3D11_CPU_ACCESS_READ) + info.access |= VK_ACCESS_HOST_READ_BIT; + } if (pDesc->MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE) info.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;