[host] dxgi: refactor dxgi_copyFrame

This commit is contained in:
Geoffrey McRae 2022-05-04 09:27:52 +10:00
parent 15334c89d6
commit c8a5293645

View File

@ -179,26 +179,45 @@ static void d3d11_free(void)
this = NULL;
}
static bool d3d11_copyFrame(Texture * tex, ID3D11Texture2D * src)
static void copyFrameFull(Texture * tex, ID3D11Texture2D * src)
{
struct D3D11TexImpl * teximpl = TEXIMPL(*tex);
ID3D11Texture2D * dst = teximpl->gpu ? teximpl->gpu : teximpl->cpu;
INTERLOCKED_SECTION(dxgi->deviceContextLock,
{
tex->copyTime = microtime();
ID3D11Texture2D * dst = teximpl->cpu;
if (tex->texDamageCount < 0)
{
if (!teximpl->gpu)
ID3D11DeviceContext_CopyResource(dxgi->deviceContext,
(ID3D11Resource *)dst, (ID3D11Resource *)src);
else
{
for (int i = 0; i < tex->texDamageCount; ++i)
{
FrameDamageRect * rect = tex->texDamageRects + i;
D3D11_BOX box =
{
.left = rect->x,
.top = rect->y,
.front = 0,
.back = 1,
.right = rect->x + rect->width ,
.bottom = rect->y + rect->height,
};
ID3D11DeviceContext_CopySubresourceRegion(dxgi->deviceContext,
(ID3D11Resource *)dst, 0, box.left, box.top, 0,
(ID3D11Resource *)src, 0, &box);
}
}
}
static void copyFrameDownsampled(Texture * tex, ID3D11Texture2D * src)
{
struct D3D11TexImpl * teximpl = TEXIMPL(*tex);
ID3D11Texture2D * dst = teximpl->gpu;
if (tex->texDamageCount < 0)
ID3D11DeviceContext_ResolveSubresource(dxgi->deviceContext,
(ID3D11Resource *)dst, 0,
(ID3D11Resource *)src, 0,
dxgi->dxgiFormat);
}
else
{
for (int i = 0; i < tex->texDamageCount; ++i)
@ -219,8 +238,6 @@ static bool d3d11_copyFrame(Texture * tex, ID3D11Texture2D * src)
}
}
if (teximpl->gpu)
{
ID3D11DeviceContext_GenerateMips(dxgi->deviceContext, teximpl->srv);
if (tex->texDamageCount < 0)
ID3D11DeviceContext_CopySubresourceRegion(dxgi->deviceContext,
@ -248,6 +265,19 @@ static bool d3d11_copyFrame(Texture * tex, ID3D11Texture2D * src)
}
}
static bool d3d11_copyFrame(Texture * tex, ID3D11Texture2D * src)
{
struct D3D11TexImpl * teximpl = TEXIMPL(*tex);
INTERLOCKED_SECTION(dxgi->deviceContextLock,
{
tex->copyTime = microtime();
if (teximpl->gpu)
copyFrameDownsampled(tex, src);
else
copyFrameFull(tex, src);
ID3D11DeviceContext_Flush(dxgi->deviceContext);
});
return true;