[d3d11] Introduce methods for dirty region tracking for mapped images

This commit is contained in:
Philip Rebohle 2022-09-05 04:57:31 +02:00
parent 1bed39f266
commit 40ffac72d9
1 changed files with 77 additions and 0 deletions

View File

@ -61,6 +61,15 @@ namespace dxvk {
};
/**
* \brief Region
*/
struct D3D11_COMMON_TEXTURE_REGION {
VkOffset3D Offset;
VkExtent3D Extent;
};
/**
* \brief D3D11 common texture object
*
@ -292,6 +301,72 @@ namespace dxvk {
}
}
/**
* \brief Adds a dirty region
*
* This region will be updated on Unmap.
* \param [in] Subresource Subresource index
* \param [in] Offset Region offset
* \param [in] Extent Region extent
*/
void AddDirtyRegion(UINT Subresource, VkOffset3D Offset, VkExtent3D Extent) {
D3D11_COMMON_TEXTURE_REGION region;
region.Offset = Offset;
region.Extent = Extent;
if (Subresource < m_buffers.size())
m_buffers[Subresource].dirtyRegions.push_back(region);
}
/**
* \brief Clears dirty regions
*
* Removes all dirty regions from the given subresource.
* \param [in] Subresource Subresource index
*/
void ClearDirtyRegions(UINT Subresource) {
if (Subresource < m_buffers.size())
m_buffers[Subresource].dirtyRegions.clear();
}
/**
* \brief Counts dirty regions
*
* \param [in] Subresource Subresource index
* \returns Dirty region count
*/
UINT GetDirtyRegionCount(UINT Subresource) {
return (Subresource < m_buffers.size())
? UINT(m_buffers[Subresource].dirtyRegions.size())
: UINT(0);
}
/**
* \brief Retrieves dirty regions
*
* \param [in] Subresource Subresource index
* \param [in] Region Region index
* \returns Dirty region
*/
D3D11_COMMON_TEXTURE_REGION GetDirtyRegionCount(UINT Subresource, UINT Region) {
return m_buffers[Subresource].dirtyRegions[Region];
}
/**
* \brief Checks whether or not to track dirty regions
*
* If this returns true, then any functions that update the
* mapped staging buffer must also track dirty regions while
* the image is mapped. Otherwise, the entire image is dirty.
* \returns \c true if dirty regions must be tracked
*/
bool NeedsDirtyRegionTracking() const {
// Only set this for images where Map can't return a pointer
return m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER
&& m_desc.Usage == D3D11_USAGE_DEFAULT
&& m_desc.TextureLayout == D3D11_TEXTURE_LAYOUT_UNDEFINED;
}
/**
* \brief Computes pixel offset into mapped buffer
*
@ -379,6 +454,8 @@ namespace dxvk {
struct MappedBuffer {
Rc<DxvkBuffer> buffer;
DxvkBufferSliceHandle slice;
std::vector<D3D11_COMMON_TEXTURE_REGION> dirtyRegions;
};
struct MappedInfo {