diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 6ccfe851a..0398c98f4 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -58,53 +58,8 @@ namespace dxvk { } - DxvkBufferSlice D3D11Buffer::GetBufferSlice() const { - return DxvkBufferSlice(m_buffer, 0, m_desc.ByteWidth); - } - - - HRESULT D3D11Buffer::Map( - D3D11DeviceContext* pContext, - D3D11_MAP MapType, - UINT MapFlags, - D3D11_MAPPED_SUBRESOURCE* pMappedSubresource) { - const Rc buffer = m_buffer; - - if (buffer->mapPtr(0) == nullptr) { - Logger::err("D3D11: Cannot map a device-local buffer"); - return E_FAIL; - } - - if (pMappedSubresource == nullptr) - return S_OK; - - if (buffer->isInUse()) { - // Don't wait if the application tells us not to - if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT) - return DXGI_ERROR_WAS_STILL_DRAWING; - - // Invalidate the buffer in order to avoid synchronization - // if the application does not need the buffer contents to - // be preserved. The No Overwrite mode does not require any - // sort of synchronization, but should be used with care. - if (MapType == D3D11_MAP_WRITE_DISCARD) { - pContext->GetDXVKContext()->invalidateBuffer(m_buffer); - } else if (MapType != D3D11_MAP_WRITE_NO_OVERWRITE) { - pContext->Flush(); - pContext->Synchronize(); - } - } - - pMappedSubresource->pData = buffer->mapPtr(0); - pMappedSubresource->RowPitch = buffer->info().size; - pMappedSubresource->DepthPitch = buffer->info().size; - return S_OK; - } - - Rc D3D11Buffer::CreateBuffer( const D3D11_BUFFER_DESC* pDesc) const { - // Gather usage information DxvkBufferCreateInfo info; info.size = pDesc->ByteWidth; info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index 727412f0f..18edafd2b 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -38,30 +38,12 @@ namespace dxvk { D3D11_BUFFER_DESC *pDesc) final; /** - * \brief Retrieves current buffer slice - * - * When the buffer gets renamed, the slice that is - * used for rendering and copy operations changes. - * May only be called from the immediate context. - * \returns Current buffer slice + * \brief Retrieves buffer slice + * \returns Buffer slice containing the entire buffer */ - DxvkBufferSlice GetBufferSlice() const; - - /** - * \brief Maps buffer - * - * Must only be called from the immediate context. - * \param [in] pContext The immediate context - * \param [in] MapType Map type - * \param [in] MapFlags Map flags - * \param [out] pMappedSubresource Map pointer - * \return \c S_OK on success - */ - HRESULT Map( - D3D11DeviceContext* pContext, - D3D11_MAP MapType, - UINT MapFlags, - D3D11_MAPPED_SUBRESOURCE* pMappedSubresource); + DxvkBufferSlice GetBufferSlice() const { + return DxvkBufferSlice(m_buffer, 0, m_buffer->info().size); + } private: diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 15ff2bd74..b7b3d5c11 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -178,8 +178,38 @@ namespace dxvk { pResource->GetType(&resourceDim); if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) { - D3D11Buffer* resource = static_cast(pResource); - return resource->Map(this, MapType, MapFlags, pMappedResource); + const D3D11Buffer* resource = static_cast(pResource); + const Rc buffer = resource->GetBufferSlice().buffer(); + + 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()) { + // Don't wait if the application tells us not to + if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT) + return DXGI_ERROR_WAS_STILL_DRAWING; + + // Invalidate the buffer in order to avoid synchronization + // if the application does not need the buffer contents to + // be preserved. The No Overwrite mode does not require any + // sort of synchronization, but should be used with care. + if (MapType == D3D11_MAP_WRITE_DISCARD) { + m_context->invalidateBuffer(buffer); + } else if (MapType != D3D11_MAP_WRITE_NO_OVERWRITE) { + this->Flush(); + this->Synchronize(); + } + } + + pMappedResource->pData = buffer->mapPtr(0); + pMappedResource->RowPitch = buffer->info().size; + pMappedResource->DepthPitch = buffer->info().size; + return S_OK; } else { Logger::err("D3D11: Mapping of image resources currently not supported"); return E_NOTIMPL;