From 15eff234ec31c67c3076e0f58466baafcba1840c Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 28 Mar 2025 14:11:48 +0000 Subject: [PATCH] [idd] driver: make indirectCopy functional --- idd/LGIdd/CFrameBufferPool.cpp | 4 +++- idd/LGIdd/CFrameBufferPool.h | 4 +++- idd/LGIdd/CFrameBufferResource.cpp | 17 +++++++++++++++++ idd/LGIdd/CFrameBufferResource.h | 2 ++ idd/LGIdd/CIndirectDeviceContext.cpp | 17 ++++++++++++++--- idd/LGIdd/CIndirectDeviceContext.h | 1 + idd/LGIdd/CSwapChainProcessor.cpp | 5 ++++- 7 files changed, 44 insertions(+), 6 deletions(-) diff --git a/idd/LGIdd/CFrameBufferPool.cpp b/idd/LGIdd/CFrameBufferPool.cpp index 48a17417..ffd3b49e 100644 --- a/idd/LGIdd/CFrameBufferPool.cpp +++ b/idd/LGIdd/CFrameBufferPool.cpp @@ -14,7 +14,9 @@ void CFrameBufferPool::Reset() m_buffers[i].Reset(); } -CFrameBufferResource * CFrameBufferPool::Get(const CIndirectDeviceContext::PreparedFrameBuffer& buffer, size_t minSize) +CFrameBufferResource * CFrameBufferPool::Get( + const CIndirectDeviceContext::PreparedFrameBuffer& buffer, + size_t minSize) { if (buffer.frameIndex > ARRAYSIZE(m_buffers) - 1) return nullptr; diff --git a/idd/LGIdd/CFrameBufferPool.h b/idd/LGIdd/CFrameBufferPool.h index f6a0de4a..70c32207 100644 --- a/idd/LGIdd/CFrameBufferPool.h +++ b/idd/LGIdd/CFrameBufferPool.h @@ -16,5 +16,7 @@ class CFrameBufferPool void Init(CSwapChainProcessor * swapChain); void Reset(); - CFrameBufferResource* CFrameBufferPool::Get(const CIndirectDeviceContext::PreparedFrameBuffer& buffer, size_t minSize); + CFrameBufferResource* CFrameBufferPool::Get( + const CIndirectDeviceContext::PreparedFrameBuffer& buffer, + size_t minSize); }; \ No newline at end of file diff --git a/idd/LGIdd/CFrameBufferResource.cpp b/idd/LGIdd/CFrameBufferResource.cpp index 3fdcb2bf..cebf65af 100644 --- a/idd/LGIdd/CFrameBufferResource.cpp +++ b/idd/LGIdd/CFrameBufferResource.cpp @@ -50,6 +50,17 @@ bool CFrameBufferResource::Init(CSwapChainProcessor * swapChain, uint8_t * base, IID_PPV_ARGS(&m_res) ); resName = L"STAGING"; + + if (SUCCEEDED(hr)) + { + D3D12_RANGE range = {0, 0}; + hr = m_res->Map(0, &range, &m_map); + if (FAILED(hr)) + { + DEBUG_ERROR_HR(hr, "Failed to map the resource"); + return false; + } + } } else { @@ -84,6 +95,12 @@ bool CFrameBufferResource::Init(CSwapChainProcessor * swapChain, uint8_t * base, void CFrameBufferResource::Reset() { + if (m_map) + { + m_res->Unmap(0, NULL); + m_map = NULL; + } + m_base = nullptr; m_size = 0; m_res.Reset(); diff --git a/idd/LGIdd/CFrameBufferResource.h b/idd/LGIdd/CFrameBufferResource.h index 22cbe9fd..1ec6a2f4 100644 --- a/idd/LGIdd/CFrameBufferResource.h +++ b/idd/LGIdd/CFrameBufferResource.h @@ -17,6 +17,7 @@ class CFrameBufferResource uint8_t * m_base; size_t m_size; ComPtr m_res; + void * m_map; public: bool Init(CSwapChainProcessor * swapChain, uint8_t * base, size_t size); @@ -25,6 +26,7 @@ class CFrameBufferResource bool IsValid() { return m_valid; } uint8_t * GetBase() { return m_base; } size_t GetSize() { return m_size; } + void * GetMap() { return m_map; } ComPtr Get() { return m_res; } }; diff --git a/idd/LGIdd/CIndirectDeviceContext.cpp b/idd/LGIdd/CIndirectDeviceContext.cpp index 255be894..7a5a5e23 100644 --- a/idd/LGIdd/CIndirectDeviceContext.cpp +++ b/idd/LGIdd/CIndirectDeviceContext.cpp @@ -490,11 +490,22 @@ CIndirectDeviceContext::PreparedFrameBuffer CIndirectDeviceContext::PrepareFrame return result; } +void CIndirectDeviceContext::WriteFrameBuffer(void* src, size_t offset, size_t len, bool setWritePos) +{ + KVMFRFrame * fi = (KVMFRFrame*)lgmpHostMemPtr(m_frameMemory[m_frameIndex]); + FrameBuffer * fb = (FrameBuffer*)(((uint8_t*)fi) + fi->offset); + + memcpy( + (void *)((uintptr_t)fb->data + offset), + (void *)((uintptr_t)src + offset), + len); + + if (setWritePos) + fb->wp = (uint32_t)(offset + len); +} + void CIndirectDeviceContext::FinalizeFrameBuffer() { - if (!m_lgmp || !m_frameQueue) - return; - KVMFRFrame * fi = (KVMFRFrame*)lgmpHostMemPtr(m_frameMemory[m_frameIndex]); FrameBuffer * fb = (FrameBuffer *)(((uint8_t*)fi) + fi->offset); fb->wp = m_height * m_pitch; diff --git a/idd/LGIdd/CIndirectDeviceContext.h b/idd/LGIdd/CIndirectDeviceContext.h index c84f0d28..49cb14c4 100644 --- a/idd/LGIdd/CIndirectDeviceContext.h +++ b/idd/LGIdd/CIndirectDeviceContext.h @@ -95,6 +95,7 @@ public: }; PreparedFrameBuffer PrepareFrameBuffer(int width, int height, int pitch, DXGI_FORMAT format); + void WriteFrameBuffer(void* src, size_t offset, size_t len, bool setWritePos); void FinalizeFrameBuffer(); void SendCursor(const IDARG_OUT_QUERY_HWCURSOR & info, const BYTE * data); diff --git a/idd/LGIdd/CSwapChainProcessor.cpp b/idd/LGIdd/CSwapChainProcessor.cpp index db609450..56d58833 100644 --- a/idd/LGIdd/CSwapChainProcessor.cpp +++ b/idd/LGIdd/CSwapChainProcessor.cpp @@ -216,5 +216,8 @@ void CSwapChainProcessor::SwapChainNewFrame(ComPtr acquiredBuffer m_dx12Device->GetCopyQueue().Wait(); m_dx12Device->GetCopyQueue().Reset(); - m_devContext->FinalizeFrameBuffer(); + if (m_dx12Device->IsIndirectCopy()) + m_devContext->WriteFrameBuffer(fbRes->GetMap(), 0, fbRes->GetSize(), true); + else + m_devContext->FinalizeFrameBuffer(); } \ No newline at end of file