1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-03 13:24:20 +01:00

[d3d11] Re-implement direct image mapping (disabled by default)

We cannot enable this by default yet because it may break some games.
This commit is contained in:
Philip Rebohle 2018-03-14 16:40:28 +01:00
parent 155bd32e22
commit 3b20c71894
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 76 additions and 55 deletions

View File

@ -189,13 +189,30 @@ namespace dxvk {
if (pMappedResource == nullptr)
return S_FALSE;
// Parameter validation was successful
VkImageSubresource subresource =
pResource->GetSubresourceFromIndex(
VK_IMAGE_ASPECT_COLOR_BIT, Subresource);
pResource->SetMappedSubresource(subresource);
// Query format info in order to compute
if (pResource->GetMapMode() == D3D11_COMMON_TEXTURE_MAP_MODE_DIRECT) {
const VkImageType imageType = mappedImage->info().type;
// Wait for the resource to become available
if (!WaitForResource(mappedImage, MapFlags))
return DXGI_ERROR_WAS_STILL_DRAWING;
// Query the subresource's memory layout and hope that
// the application respects the returned pitch values.
VkSubresourceLayout layout = mappedImage->querySubresourceLayout(subresource);
pMappedResource->pData = mappedImage->mapPtr(layout.offset);
pMappedResource->RowPitch = imageType >= VK_IMAGE_TYPE_2D ? layout.rowPitch : layout.size;
pMappedResource->DepthPitch = imageType >= VK_IMAGE_TYPE_3D ? layout.depthPitch : layout.size;
return S_OK;
} else {
// Query format info which we need to compute
// the row pitch and layer pitch properly.
const DxvkFormatInfo* formatInfo = imageFormatInfo(mappedImage->info().format);
@ -205,9 +222,9 @@ namespace dxvk {
DxvkPhysicalBufferSlice physicalSlice;
// When using any map mode which requires the image contents
// to be preserved, copy the image's contents into the buffer.
if (MapType == D3D11_MAP_WRITE_DISCARD) {
// We do not have to preserve the contents of the
// buffer if the entire image gets discarded.
physicalSlice = mappedBuffer->allocPhysicalSlice();
physicalSlice.resource()->acquire();
@ -219,8 +236,9 @@ namespace dxvk {
cPhysicalSlice.resource()->release();
});
} else {
// We may have to copy the current image contents into the
// mapped buffer if the GPU has write access to the image.
// When using any map mode which requires the image contents
// to be preserved, and if the GPU has write access to the
// image, copy the current image contents into the buffer.
const bool copyExistingData = pResource->Desc()->Usage == D3D11_USAGE_STAGING;
if (copyExistingData) {
@ -254,6 +272,7 @@ namespace dxvk {
pMappedResource->DepthPitch = formatInfo->elementSize * blockCount.width * blockCount.height;
return S_OK;
}
}
void D3D11ImmediateContext::UnmapImage(
@ -286,6 +305,8 @@ namespace dxvk {
cSrcBuffer, 0, { 0u, 0u });
});
}
pResource->ClearMappedSubresource();
}

View File

@ -203,7 +203,7 @@ namespace dxvk {
// 2. Since the image will most likely be read for rendering by the GPU,
// writing the image to device-local image may be more efficient than
// reading its contents from host-visible memory.
if ((m_desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ) == 0)
if (m_desc.Usage == D3D11_USAGE_DYNAMIC)
return D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER;
// Images that can be read by the host should be mapped directly in