mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +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:
parent
155bd32e22
commit
3b20c71894
@ -189,13 +189,30 @@ namespace dxvk {
|
|||||||
if (pMappedResource == nullptr)
|
if (pMappedResource == nullptr)
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
|
// Parameter validation was successful
|
||||||
VkImageSubresource subresource =
|
VkImageSubresource subresource =
|
||||||
pResource->GetSubresourceFromIndex(
|
pResource->GetSubresourceFromIndex(
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT, Subresource);
|
VK_IMAGE_ASPECT_COLOR_BIT, Subresource);
|
||||||
|
|
||||||
pResource->SetMappedSubresource(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.
|
// the row pitch and layer pitch properly.
|
||||||
const DxvkFormatInfo* formatInfo = imageFormatInfo(mappedImage->info().format);
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(mappedImage->info().format);
|
||||||
|
|
||||||
@ -205,9 +222,9 @@ namespace dxvk {
|
|||||||
|
|
||||||
DxvkPhysicalBufferSlice physicalSlice;
|
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) {
|
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 = mappedBuffer->allocPhysicalSlice();
|
||||||
physicalSlice.resource()->acquire();
|
physicalSlice.resource()->acquire();
|
||||||
|
|
||||||
@ -219,8 +236,9 @@ namespace dxvk {
|
|||||||
cPhysicalSlice.resource()->release();
|
cPhysicalSlice.resource()->release();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// We may have to copy the current image contents into the
|
// When using any map mode which requires the image contents
|
||||||
// mapped buffer if the GPU has write access to the image.
|
// 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;
|
const bool copyExistingData = pResource->Desc()->Usage == D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
if (copyExistingData) {
|
if (copyExistingData) {
|
||||||
@ -254,6 +272,7 @@ namespace dxvk {
|
|||||||
pMappedResource->DepthPitch = formatInfo->elementSize * blockCount.width * blockCount.height;
|
pMappedResource->DepthPitch = formatInfo->elementSize * blockCount.width * blockCount.height;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void D3D11ImmediateContext::UnmapImage(
|
void D3D11ImmediateContext::UnmapImage(
|
||||||
@ -286,6 +305,8 @@ namespace dxvk {
|
|||||||
cSrcBuffer, 0, { 0u, 0u });
|
cSrcBuffer, 0, { 0u, 0u });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pResource->ClearMappedSubresource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ namespace dxvk {
|
|||||||
// 2. Since the image will most likely be read for rendering by the GPU,
|
// 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
|
// writing the image to device-local image may be more efficient than
|
||||||
// reading its contents from host-visible memory.
|
// 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;
|
return D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER;
|
||||||
|
|
||||||
// Images that can be read by the host should be mapped directly in
|
// Images that can be read by the host should be mapped directly in
|
||||||
|
Loading…
x
Reference in New Issue
Block a user