[d3d11] Reverted some design decisions related to buffer renaming

This commit is contained in:
Philip Rebohle 2017-12-16 13:35:11 +01:00
parent d3b2174180
commit 85120d2d01
3 changed files with 37 additions and 70 deletions

View File

@ -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<DxvkBuffer> 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<DxvkBuffer> 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

View File

@ -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:

View File

@ -178,8 +178,38 @@ namespace dxvk {
pResource->GetType(&resourceDim);
if (resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
D3D11Buffer* resource = static_cast<D3D11Buffer*>(pResource);
return resource->Map(this, MapType, MapFlags, pMappedResource);
const D3D11Buffer* resource = static_cast<D3D11Buffer*>(pResource);
const Rc<DxvkBuffer> 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;