mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
Move buffer copies to render thread if they happen in the main thread.
This commit is contained in:
parent
b867961000
commit
882f371de4
1 changed files with 51 additions and 16 deletions
|
|
@ -355,6 +355,8 @@ enum class RenderCommandType
|
|||
SetRenderState,
|
||||
DestructResource,
|
||||
UnlockTextureRect,
|
||||
UnlockBuffer16,
|
||||
UnlockBuffer32,
|
||||
Present,
|
||||
StretchRect,
|
||||
SetRenderTarget,
|
||||
|
|
@ -398,6 +400,11 @@ struct RenderCommand
|
|||
GuestTexture* texture;
|
||||
} unlockTextureRect;
|
||||
|
||||
struct
|
||||
{
|
||||
GuestBuffer* buffer;
|
||||
} unlockBuffer;
|
||||
|
||||
struct
|
||||
{
|
||||
GuestDevice* device;
|
||||
|
|
@ -1170,9 +1177,7 @@ static void ExecuteCopyCommandList(const T& function)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
static void UnlockBuffer(GuestBuffer* buffer)
|
||||
{
|
||||
if (!buffer->lockedReadOnly)
|
||||
static void UnlockBufferImpl(GuestBuffer* buffer)
|
||||
{
|
||||
auto uploadBuffer = g_device->createBuffer(RenderBufferDesc::UploadBuffer(buffer->dataSize));
|
||||
|
||||
|
|
@ -1193,6 +1198,34 @@ static void UnlockBuffer(GuestBuffer* buffer)
|
|||
g_copyCommandList->copyBufferRegion(buffer->buffer->at(0), uploadBuffer->at(0), buffer->dataSize);
|
||||
});
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void UnlockBuffer(GuestBuffer* buffer)
|
||||
{
|
||||
if (!buffer->lockedReadOnly)
|
||||
{
|
||||
if (GetCurrentThreadId() == g_mainThreadId)
|
||||
{
|
||||
RenderCommand cmd;
|
||||
cmd.type = (sizeof(T) == 2) ? RenderCommandType::UnlockBuffer16 : RenderCommandType::UnlockBuffer32;
|
||||
cmd.unlockBuffer.buffer = buffer;
|
||||
g_renderQueue.enqueue(cmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnlockBufferImpl<T>(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcUnlockBuffer16(const RenderCommand& cmd)
|
||||
{
|
||||
UnlockBufferImpl<uint16_t>(cmd.unlockBuffer.buffer);
|
||||
}
|
||||
|
||||
static void ProcUnlockBuffer32(const RenderCommand& cmd)
|
||||
{
|
||||
UnlockBufferImpl<uint32_t>(cmd.unlockBuffer.buffer);
|
||||
}
|
||||
|
||||
static void UnlockVertexBuffer(GuestBuffer* buffer)
|
||||
|
|
@ -2777,6 +2810,8 @@ static std::thread g_renderThread([]
|
|||
case RenderCommandType::SetRenderState: ProcSetRenderState(cmd); break;
|
||||
case RenderCommandType::DestructResource: ProcDestructResource(cmd); break;
|
||||
case RenderCommandType::UnlockTextureRect: ProcUnlockTextureRect(cmd); break;
|
||||
case RenderCommandType::UnlockBuffer16: ProcUnlockBuffer16(cmd); break;
|
||||
case RenderCommandType::UnlockBuffer32: ProcUnlockBuffer32(cmd); break;
|
||||
case RenderCommandType::Present: ProcPresent(cmd); break;
|
||||
case RenderCommandType::StretchRect: ProcStretchRect(cmd); break;
|
||||
case RenderCommandType::SetRenderTarget: ProcSetRenderTarget(cmd); break;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue