mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-09 08:41:31 +00:00
[idd] transport: abstract LGMP implementation
Introduce transport, frame, and control interfaces with an LGMP factory backend. Move LGMP and IVSHMEM implementation details under transport/lgmp and expose direct frame-buffer memory through a neutral capability.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#include "d3d/CD3D12Device.h"
|
||||
#include "CDebug.h"
|
||||
|
||||
bool CD3D12Device::m_indirectCopy = false;
|
||||
bool CD3D12Device::s_directHeapFailed = false;
|
||||
|
||||
CD3D12Device::CD3D12Device(LUID adapterLuid) :
|
||||
m_adapterLuid(adapterLuid),
|
||||
@@ -60,12 +60,14 @@ static void CALLBACK _D3D12DebugCallback(
|
||||
description);
|
||||
}
|
||||
|
||||
CD3D12Device::InitResult CD3D12Device::Init(CIVSHMEM &ivshmem,
|
||||
UINT64 &alignSize, bool enableCompute)
|
||||
CD3D12Device::InitResult CD3D12Device::Init(
|
||||
const DirectFrameBufferMemory& directMemory,
|
||||
UINT64& alignSize, bool enableCompute)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
m_computeEnabled = enableCompute;
|
||||
m_indirectCopy = !directMemory || s_directHeapFailed;
|
||||
|
||||
hr = CreateDXGIFactory2(m_debug ? DXGI_CREATE_FACTORY_DEBUG : 0, IID_PPV_ARGS(&m_factory));
|
||||
if (FAILED(hr))
|
||||
@@ -105,34 +107,37 @@ CD3D12Device::InitResult CD3D12Device::Init(CIVSHMEM &ivshmem,
|
||||
|
||||
if (!m_indirectCopy)
|
||||
{
|
||||
hr = m_device->OpenExistingHeapFromAddress(ivshmem.GetMem(), IID_PPV_ARGS(&m_ivshmemHeap));
|
||||
hr = m_device->OpenExistingHeapFromAddress(
|
||||
directMemory.address, IID_PPV_ARGS(&m_transportHeap));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DEBUG_ERROR_HR(hr, "Failed to open IVSHMEM as a D3D12Heap");
|
||||
m_indirectCopy = true;
|
||||
DEBUG_ERROR_HR(hr,
|
||||
"Failed to open transport memory as a D3D12 heap");
|
||||
s_directHeapFailed = true;
|
||||
return InitResult::RETRY;
|
||||
}
|
||||
m_ivshmemHeap->SetName(L"IVSHMEM");
|
||||
m_transportHeap->SetName(L"Transport Memory");
|
||||
|
||||
D3D12_HEAP_DESC heapDesc = m_ivshmemHeap->GetDesc();
|
||||
D3D12_HEAP_DESC heapDesc = m_transportHeap->GetDesc();
|
||||
alignSize = heapDesc.Alignment;
|
||||
m_ivshmemTextureSupported =
|
||||
m_directTextureSupported =
|
||||
(heapDesc.Flags & D3D12_HEAP_FLAG_SHARED_CROSS_ADAPTER) &&
|
||||
!(heapDesc.Flags & D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES);
|
||||
|
||||
// test that the heap is usable
|
||||
if (!HeapTest())
|
||||
{
|
||||
DEBUG_WARN("Unable to create resources in the IVSHMEM heap, falling back to indirect copy");
|
||||
DEBUG_WARN("Unable to create resources in transport memory, "
|
||||
"falling back to indirect copy");
|
||||
|
||||
// failure often results in the device being removed and we need to completely reinit when this occurs
|
||||
m_indirectCopy = true;
|
||||
s_directHeapFailed = true;
|
||||
return InitResult::RETRY;
|
||||
}
|
||||
|
||||
DEBUG_INFO("Using IVSHMEM as a D3D12Heap");
|
||||
if (!m_ivshmemTextureSupported)
|
||||
DEBUG_WARN("IVSHMEM heap does not support placed textures");
|
||||
DEBUG_INFO("Using transport memory as a D3D12 heap");
|
||||
if (!m_directTextureSupported)
|
||||
DEBUG_WARN("Transport memory does not support placed textures");
|
||||
}
|
||||
|
||||
if (!m_copyQueue.Init(m_device.Get(), D3D12_COMMAND_LIST_TYPE_COPY,
|
||||
@@ -182,7 +187,7 @@ bool CD3D12Device::HeapTest()
|
||||
|
||||
ComPtr<ID3D12Resource> resource;
|
||||
hr = m_device->CreatePlacedResource(
|
||||
m_ivshmemHeap.Get(),
|
||||
m_transportHeap.Get(),
|
||||
0,
|
||||
&desc,
|
||||
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||
@@ -190,7 +195,8 @@ bool CD3D12Device::HeapTest()
|
||||
IID_PPV_ARGS(&resource));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DEBUG_ERROR_HR(hr, "Failed to create the ivshmem ID3D12Resource");
|
||||
DEBUG_ERROR_HR(hr,
|
||||
"Failed to create the transport-memory ID3D12Resource");
|
||||
return false;
|
||||
}
|
||||
resource->SetName(L"HeapTest");
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
#include <dxgi1_5.h>
|
||||
#include <d3d12.h>
|
||||
|
||||
#include "transport/CIVSHMEM.h"
|
||||
#include "d3d/CD3D12CommandQueue.h"
|
||||
#include "transport/TransportTypes.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
@@ -37,8 +37,9 @@ struct CD3D12Device
|
||||
LUID m_adapterLuid;
|
||||
bool m_debug;
|
||||
|
||||
// static as this needs to persist if set
|
||||
static bool m_indirectCopy;
|
||||
// A failed direct heap can remove the device. Preserve the fallback for
|
||||
// the replacement device so initialization does not retry forever.
|
||||
static bool s_directHeapFailed;
|
||||
|
||||
ComPtr<ID3D12Debug6 > m_dxDebug;
|
||||
ComPtr<ID3D12InfoQueue1> m_infoQueue;
|
||||
@@ -47,12 +48,13 @@ struct CD3D12Device
|
||||
ComPtr<IDXGIFactory5> m_factory;
|
||||
ComPtr<IDXGIAdapter1> m_adapter;
|
||||
ComPtr<ID3D12Device3> m_device;
|
||||
ComPtr<ID3D12Heap > m_ivshmemHeap;
|
||||
ComPtr<ID3D12Heap > m_transportHeap;
|
||||
|
||||
CD3D12CommandQueue m_copyQueue;
|
||||
CD3D12CommandQueue m_computeQueue;
|
||||
bool m_computeEnabled = false;
|
||||
bool m_ivshmemTextureSupported = false;
|
||||
bool m_computeEnabled = false;
|
||||
bool m_indirectCopy = true;
|
||||
bool m_directTextureSupported = false;
|
||||
|
||||
bool HeapTest();
|
||||
|
||||
@@ -67,8 +69,8 @@ struct CD3D12Device
|
||||
SUCCESS
|
||||
};
|
||||
|
||||
InitResult Init(CIVSHMEM &ivshmem, UINT64 &alignSize,
|
||||
bool enableCompute);
|
||||
InitResult Init(const DirectFrameBufferMemory& directMemory,
|
||||
UINT64& alignSize, bool enableCompute);
|
||||
void DeInit();
|
||||
|
||||
// Wait for all command queues to finish in-flight GPU work and run their
|
||||
@@ -77,9 +79,9 @@ struct CD3D12Device
|
||||
void WaitForIdle();
|
||||
|
||||
ComPtr<ID3D12Device3> GetDevice() { return m_device; }
|
||||
ComPtr<ID3D12Heap > GetHeap() { return m_ivshmemHeap; }
|
||||
bool IsIndirectCopy() { return m_indirectCopy; }
|
||||
bool CanUseIVSHMEMTexture() { return m_ivshmemTextureSupported; }
|
||||
ComPtr<ID3D12Heap > GetTransportHeap() { return m_transportHeap; }
|
||||
bool IsIndirectCopy() const { return m_indirectCopy; }
|
||||
bool CanUseDirectTexture() const { return m_directTextureSupported; }
|
||||
|
||||
CD3D12CommandSlot * GetCopySlot ();
|
||||
CD3D12CommandSlot * GetCopySlot (unsigned frameIndex);
|
||||
|
||||
Reference in New Issue
Block a user