Commit 2115b896 authored by Joshua Ashton's avatar Joshua Ashton 🐸

[d3d9] Make staging resource on the fly for RTs that get locked, reset dirty...

[d3d9] Make staging resource on the fly for RTs that get locked, reset dirty flags and correct MarkDirty overflows.
parent 46654921
Pipeline #46 passed with stage
in 1 minute and 36 seconds
......@@ -30,17 +30,38 @@ namespace dxup {
}
void DXUPResource::MarkDirty(UINT slice, UINT mip) {
m_dirtySubresources[slice] = 1 << mip;
m_dirtySubresources[slice] = 1ull << mip;
}
void DXUPResource::MakeClean() {
bool dirty = false;
for (uint32_t slice = 0; slice < m_slices; slice++) {
uint64_t dirtyFlags = m_dirtySubresources[slice];
if (m_dirtySubresources[slice] != 0)
dirty = true;
}
if (!dirty)
return;
// This is needed for RTs, we only want staging buffers for them if they NEED them.
if (GetStaging() == nullptr) {
D3D11_TEXTURE2D_DESC desc;
ID3D11Texture2D* tex = GetResourceAs<ID3D11Texture2D>();
tex->GetDesc(&desc);
makeStagingDesc(desc, 0, D3DFMT_UNKNOWN);
m_device->GetD3D11Device()->CreateTexture2D(&desc, nullptr, (ID3D11Texture2D**)&m_staging);
}
for (uint32_t slice = 0; slice < m_slices; slice++) {
uint64_t* dirtyFlags = &m_dirtySubresources[slice];
for (uint64_t mip = 0; mip < m_mips; mip++) {
UINT subresource = D3D11CalcSubresource(mip, slice, m_mips);
if (dirtyFlags & (1ull << mip))
m_device->GetContext()->CopySubresourceRegion(GetMapping(), subresource, 0, 0, 0, GetResource(), subresource, nullptr);
if (*dirtyFlags & (1ull << mip))
m_device->GetContext()->CopySubresourceRegion(GetStaging(), subresource, 0, 0, 0, GetResource(), subresource, nullptr);
}
*dirtyFlags = 0;
}
}
......@@ -60,7 +81,7 @@ namespace dxup {
else
m_stagingRects[subresource] = *pRect;
if (HasStaging() && !(Flags & D3DLOCK_DISCARD) && !(Flags & D3DLOCK_NOOVERWRITE) && !(Usage & D3DUSAGE_WRITEONLY))
if (!(Flags & D3DLOCK_DISCARD) && !(Flags & D3DLOCK_NOOVERWRITE) && !(Usage & D3DUSAGE_WRITEONLY))
MakeClean();
D3D11_MAPPED_SUBRESOURCE res;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment