[idd] debug: add debug defines and make use of them

This commit is contained in:
Geoffrey McRae 2025-03-16 16:31:44 +00:00
parent 0db9d3a27b
commit 09df8c41aa
14 changed files with 99 additions and 89 deletions

View File

@ -54,7 +54,7 @@ HRESULT CD3D11Device::Init()
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
DBGPRINT("Feature Level: 0x%x", featureLevel); DEBUG_INFO("Feature Level: 0x%x", featureLevel);
hr = device.As(&m_device); hr = device.As(&m_device);
if (FAILED(hr)) if (FAILED(hr))

View File

@ -13,7 +13,7 @@ bool CD3D12CommandQueue::Init(ID3D12Device3 * device, D3D12_COMMAND_LIST_TYPE ty
hr = device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_queue)); hr = device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_queue));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the CommandQueue (%ls)", name); DEBUG_ERROR_HR(hr, "Failed to create the CommandQueue (%ls)", name);
return false; return false;
} }
m_queue->SetName(name); m_queue->SetName(name);
@ -21,14 +21,14 @@ bool CD3D12CommandQueue::Init(ID3D12Device3 * device, D3D12_COMMAND_LIST_TYPE ty
hr = device->CreateCommandAllocator(type, IID_PPV_ARGS(&m_allocator)); hr = device->CreateCommandAllocator(type, IID_PPV_ARGS(&m_allocator));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the CommandAllocator (%ls)", name); DEBUG_ERROR_HR(hr, "Failed to create the CommandAllocator (%ls)", name);
return false; return false;
} }
hr = device->CreateCommandList(0, type, m_allocator.Get(), NULL, IID_PPV_ARGS(&m_gfxList)); hr = device->CreateCommandList(0, type, m_allocator.Get(), NULL, IID_PPV_ARGS(&m_gfxList));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the Graphics CommandList (%ls)", name); DEBUG_ERROR_HR(hr, "Failed to create the Graphics CommandList (%ls)", name);
return false; return false;
} }
m_gfxList->SetName(name); m_gfxList->SetName(name);
@ -36,27 +36,27 @@ bool CD3D12CommandQueue::Init(ID3D12Device3 * device, D3D12_COMMAND_LIST_TYPE ty
m_cmdList = m_gfxList; m_cmdList = m_gfxList;
if (!m_cmdList) if (!m_cmdList)
{ {
DBGPRINT_HR(hr, "Failed to get the CommandList (%ls)", name); DEBUG_ERROR_HR(hr, "Failed to get the CommandList (%ls)", name);
return false; return false;
} }
hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence)); hr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the Fence (%ls)", name); DEBUG_ERROR_HR(hr, "Failed to create the Fence (%ls)", name);
return false; return false;
} }
m_event.Attach(CreateEvent(NULL, FALSE, FALSE, NULL)); m_event.Attach(CreateEvent(NULL, FALSE, FALSE, NULL));
if (m_event.Get() == INVALID_HANDLE_VALUE) if (m_event.Get() == INVALID_HANDLE_VALUE)
{ {
DBGPRINT_HR(GetLastError(), "Failed to create the completion event (%ls)", name); DEBUG_ERROR_HR(GetLastError(), "Failed to create the completion event (%ls)", name);
return false; return false;
} }
m_name = name; m_name = name;
m_fenceValue = 0; m_fenceValue = 0;
DBGPRINT("Created CD3D12CommandQueue(%ls)", name); DEBUG_INFO("Created CD3D12CommandQueue(%ls)", name);
return true; return true;
} }
@ -65,7 +65,7 @@ bool CD3D12CommandQueue::Execute()
HRESULT hr = m_gfxList->Close(); HRESULT hr = m_gfxList->Close();
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to close the command list (%ls)", m_name); DEBUG_ERROR_HR(hr, "Failed to close the command list (%ls)", m_name);
return false; return false;
} }
@ -75,7 +75,7 @@ bool CD3D12CommandQueue::Execute()
m_queue->Signal(m_fence.Get(), ++m_fenceValue); m_queue->Signal(m_fence.Get(), ++m_fenceValue);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to set the fence signal (%ls)", m_name); DEBUG_ERROR_HR(hr, "Failed to set the fence signal (%ls)", m_name);
return false; return false;
} }
@ -98,14 +98,14 @@ bool CD3D12CommandQueue::Reset()
hr = m_allocator->Reset(); hr = m_allocator->Reset();
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to reset the command allocator (%ls)", m_name); DEBUG_ERROR_HR(hr, "Failed to reset the command allocator (%ls)", m_name);
return false; return false;
} }
hr = m_gfxList->Reset(m_allocator.Get(), NULL); hr = m_gfxList->Reset(m_allocator.Get(), NULL);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to reset the graphics command list (%ls)", m_name); DEBUG_ERROR_HR(hr, "Failed to reset the graphics command list (%ls)", m_name);
return false; return false;
} }

View File

@ -11,7 +11,7 @@ CD3D12Device::CD3D12Device(LUID adapterLuid) :
HRESULT hr = D3D12GetDebugInterface(IID_PPV_ARGS(&m_dxDebug)); HRESULT hr = D3D12GetDebugInterface(IID_PPV_ARGS(&m_dxDebug));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to get the debug interface"); DEBUG_ERROR_HR(hr, "Failed to get the debug interface");
return; return;
} }
@ -32,7 +32,7 @@ static void CALLBACK _D3D12DebugCallback(
{ {
(void)context; (void)context;
DBGPRINT("category:%d severity:%d id:%d desc:%s", DEBUG_INFO("category:%d severity:%d id:%d desc:%s",
category, category,
severity, severity,
id, id,
@ -47,21 +47,21 @@ reInit:
hr = CreateDXGIFactory2(m_debug ? DXGI_CREATE_FACTORY_DEBUG : 0, IID_PPV_ARGS(&m_factory)); hr = CreateDXGIFactory2(m_debug ? DXGI_CREATE_FACTORY_DEBUG : 0, IID_PPV_ARGS(&m_factory));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the DXGI factory"); DEBUG_ERROR_HR(hr, "Failed to create the DXGI factory");
return false; return false;
} }
hr = m_factory->EnumAdapterByLuid(m_adapterLuid, IID_PPV_ARGS(&m_adapter)); hr = m_factory->EnumAdapterByLuid(m_adapterLuid, IID_PPV_ARGS(&m_adapter));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to enumerate the adapter"); DEBUG_ERROR_HR(hr, "Failed to enumerate the adapter");
return false; return false;
} }
hr = D3D12CreateDevice(m_adapter.Get(), D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&m_device)); hr = D3D12CreateDevice(m_adapter.Get(), D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&m_device));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the DirectX12 device"); DEBUG_ERROR_HR(hr, "Failed to create the DirectX12 device");
return false; return false;
} }
@ -70,7 +70,7 @@ reInit:
hr = m_device.As(&m_infoQueue); hr = m_device.As(&m_infoQueue);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to get the ID3D12InfoQueue1 interface"); DEBUG_WARN_HR(hr, "Failed to get the ID3D12InfoQueue1 interface");
//non-fatal do not exit //non-fatal do not exit
} }
else else
@ -83,7 +83,7 @@ reInit:
hr = m_device->OpenExistingHeapFromAddress(ivshmem.GetMem(), IID_PPV_ARGS(&m_ivshmemHeap)); hr = m_device->OpenExistingHeapFromAddress(ivshmem.GetMem(), IID_PPV_ARGS(&m_ivshmemHeap));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to open IVSHMEM as a D3D12Heap"); DEBUG_ERROR_HR(hr, "Failed to open IVSHMEM as a D3D12Heap");
return false; return false;
} }
m_ivshmemHeap->SetName(L"IVSHMEM"); m_ivshmemHeap->SetName(L"IVSHMEM");
@ -94,7 +94,7 @@ reInit:
// test that the heap is usable // test that the heap is usable
if (!HeapTest()) if (!HeapTest())
{ {
DBGPRINT("Unable to create resources in the IVSHMEM heap, falling back to indirect copy"); DEBUG_WARN("Unable to create resources in the IVSHMEM heap, falling back to indirect copy");
// failure often results in the device being removed and we need to completely reinit when this occurs // failure often results in the device being removed and we need to completely reinit when this occurs
m_indirectCopy = true; m_indirectCopy = true;
@ -104,7 +104,7 @@ reInit:
goto reInit; goto reInit;
} }
DBGPRINT("Using IVSHMEM as a D3D12Heap"); DEBUG_INFO("Using IVSHMEM as a D3D12Heap");
} }
if (!m_copyQueue.Init(m_device.Get(), D3D12_COMMAND_LIST_TYPE_COPY, L"Copy")) if (!m_copyQueue.Init(m_device.Get(), D3D12_COMMAND_LIST_TYPE_COPY, L"Copy"))
@ -113,7 +113,7 @@ reInit:
//if (!m_computeQueue.Init(m_device.Get(), D3D12_COMMAND_LIST_TYPE_COMPUTE, L"Compute")) //if (!m_computeQueue.Init(m_device.Get(), D3D12_COMMAND_LIST_TYPE_COMPUTE, L"Compute"))
//return false; //return false;
DBGPRINT("Created CD3D12Device"); DEBUG_INFO("Created CD3D12Device");
return true; return true;
} }
@ -151,7 +151,7 @@ bool CD3D12Device::HeapTest()
IID_PPV_ARGS(&resource)); IID_PPV_ARGS(&resource));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the ivshmem ID3D12Resource"); DEBUG_ERROR_HR(hr, "Failed to create the ivshmem ID3D12Resource");
return false; return false;
} }
resource->SetName(L"HeapTest"); resource->SetName(L"HeapTest");
@ -161,7 +161,7 @@ bool CD3D12Device::HeapTest()
hr = m_device->GetDeviceRemovedReason(); hr = m_device->GetDeviceRemovedReason();
if (hr != S_OK) if (hr != S_OK)
{ {
DBGPRINT_HR(hr, "Device Removed"); DEBUG_ERROR_HR(hr, "Device Removed");
return false; return false;
} }

View File

@ -39,7 +39,7 @@ CDebug::CDebug()
DWORD pathLen = GetTempPathA(sizeof(tempPath), tempPath); DWORD pathLen = GetTempPathA(sizeof(tempPath), tempPath);
if (pathLen == 0) if (pathLen == 0)
{ {
DBGPRINT_HR(GetLastError(), "Failed to get the temp path"); DEBUG_ERROR_HR(GetLastError(), "Failed to get the temp path");
return; return;
} }
@ -74,11 +74,11 @@ CDebug::CDebug()
std::ofstream stream(logFile, std::ios::out | std::ios::trunc); std::ofstream stream(logFile, std::ios::out | std::ios::trunc);
if (!stream.is_open()) if (!stream.is_open())
{ {
DBGPRINT_HR(GetLastError(), "Failed to open the log file %s", logFile.c_str()); DEBUG_ERROR_HR(GetLastError(), "Failed to open the log file %s", logFile.c_str());
return; return;
} }
else else
DBGPRINT("Logging to: %s", logFile.c_str()); DEBUG_INFO("Logging to: %s", logFile.c_str());
m_stream = std::move(stream); m_stream = std::move(stream);
} }
@ -140,7 +140,7 @@ void CDebug::LogHR(CDebug::Level level, HRESULT hr, const char * function, int l
NULL NULL
)) ))
{ {
DBGPRINT("FormatMessage failed with code 0x%08x", GetLastError()); DEBUG_INFO("FormatMessage failed with code 0x%08x", GetLastError());
return; return;
} }

View File

@ -64,8 +64,17 @@ class CDebug
extern CDebug g_debug; extern CDebug g_debug;
#define DBGPRINT(kszDebugFormatString, ...) \ #define DEBUG_INFO(fmt, ...) g_debug.Log(CDebug::LEVEL_INFO, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
g_debug.Log(CDebug::LEVEL_INFO, __FUNCTION__, __LINE__, kszDebugFormatString, __VA_ARGS__) #define DEBUG_WARN(fmt, ...) g_debug.Log(CDebug::LEVEL_WARN, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_ERROR(fmt, ...) g_debug.Log(CDebug::LEVEL_ERROR, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_TRACE(fmt, ...) g_debug.Log(CDebug::LEVEL_TRACE, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_FIXME(fmt, ...) g_debug.Log(CDebug::LEVEL_FIXME, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_FATAL(fmt, ...) g_debug.Log(CDebug::LEVEL_FATAL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DBGPRINT_HR(status, kszDebugFormatString, ...) \
g_debug.LogHR(CDebug::LEVEL_INFO, status, __FUNCTION__, __LINE__, kszDebugFormatString, __VA_ARGS__) #define DEBUG_INFO_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_INFO, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_WARN_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_WARN, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_ERROR_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_ERROR, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_TRACE_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_TRACE, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_FIXME_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_FIXME, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#define DEBUG_FATAL_HR(hr, fmt, ...) g_debug.LogHR(CDebug::LEVEL_FATAL, hr, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)

View File

@ -6,7 +6,7 @@ bool CFrameBufferResource::Init(CSwapChainProcessor * swapChain, uint8_t * base,
{ {
if (size > swapChain->GetDevice()->GetMaxFrameSize()) if (size > swapChain->GetDevice()->GetMaxFrameSize())
{ {
DBGPRINT("Frame size of %lu is too large to fit in available shared ram"); DEBUG_ERROR("Frame size of %lu is too large to fit in available shared ram");
return false; return false;
} }
@ -33,7 +33,7 @@ bool CFrameBufferResource::Init(CSwapChainProcessor * swapChain, uint8_t * base,
if (swapChain->GetD3D12Device()->IsIndirectCopy()) if (swapChain->GetD3D12Device()->IsIndirectCopy())
{ {
DBGPRINT("Creating standard resource for %p", base); DEBUG_TRACE("Creating standard resource for %p", base);
D3D12_HEAP_PROPERTIES heapProps = {}; D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_READBACK; heapProps.Type = D3D12_HEAP_TYPE_READBACK;
heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
@ -53,7 +53,7 @@ bool CFrameBufferResource::Init(CSwapChainProcessor * swapChain, uint8_t * base,
} }
else else
{ {
DBGPRINT("Creating ivshmem resource for %p", base); DEBUG_TRACE("Creating ivshmem resource for %p", base);
desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER; desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER;
@ -70,7 +70,7 @@ bool CFrameBufferResource::Init(CSwapChainProcessor * swapChain, uint8_t * base,
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the FrameBuffer ID3D12Resource"); DEBUG_ERROR_HR(hr, "Failed to create the FrameBuffer ID3D12Resource");
return false; return false;
} }

View File

@ -102,7 +102,7 @@ bool CIVSHMEM::Init()
{ {
DWORD bus = it->busAddr >> 32; DWORD bus = it->busAddr >> 32;
DWORD addr = it->busAddr & 0xFFFFFFFF; DWORD addr = it->busAddr & 0xFFFFFFFF;
DBGPRINT("IVSHMEM %u%c on bus 0x%lx, device 0x%lx, function 0x%lx", DEBUG_INFO("IVSHMEM %u%c on bus 0x%lx, device 0x%lx, function 0x%lx",
i, i == shmDevice ? '*' : ' ', bus, addr >> 16, addr & 0xFFFF); i, i == shmDevice ? '*' : ' ', bus, addr >> 16, addr & 0xFFFF);
if (i == shmDevice) if (i == shmDevice)
@ -153,7 +153,7 @@ bool CIVSHMEM::Open()
IVSHMEM_SIZE size; IVSHMEM_SIZE size;
if (!DeviceIoControl(m_handle, IOCTL_IVSHMEM_REQUEST_SIZE, nullptr, 0, &size, sizeof(size), nullptr, nullptr)) if (!DeviceIoControl(m_handle, IOCTL_IVSHMEM_REQUEST_SIZE, nullptr, 0, &size, sizeof(size), nullptr, nullptr))
{ {
DBGPRINT("Failed to request ivshmem size"); DEBUG_ERROR("Failed to request ivshmem size");
return false; return false;
} }
@ -163,7 +163,7 @@ bool CIVSHMEM::Open()
config.cacheMode = IVSHMEM_CACHE_WRITECOMBINED; config.cacheMode = IVSHMEM_CACHE_WRITECOMBINED;
if (!DeviceIoControl(m_handle, IOCTL_IVSHMEM_REQUEST_MMAP, &config, sizeof(config), &map, sizeof(map), nullptr, nullptr)) if (!DeviceIoControl(m_handle, IOCTL_IVSHMEM_REQUEST_MMAP, &config, sizeof(config), &map, sizeof(map), nullptr, nullptr))
{ {
DBGPRINT("Failed to request ivshmem mmap"); DEBUG_ERROR("Failed to request ivshmem mmap");
return false; return false;
} }
@ -180,7 +180,7 @@ void CIVSHMEM::Close()
if (!DeviceIoControl(m_handle, IOCTL_IVSHMEM_RELEASE_MMAP, nullptr, 0, nullptr, 0, nullptr, nullptr)) if (!DeviceIoControl(m_handle, IOCTL_IVSHMEM_RELEASE_MMAP, nullptr, 0, nullptr, 0, nullptr, nullptr))
{ {
DBGPRINT("Failed to release ivshmem mmap"); DEBUG_ERROR("Failed to release ivshmem mmap");
return; return;
} }

View File

@ -84,7 +84,7 @@ void CIndirectDeviceContext::InitAdapter()
NTSTATUS status = IddCxAdapterInitAsync(&init, &initOut); NTSTATUS status = IddCxAdapterInitAsync(&init, &initOut);
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
DBGPRINT("IddCxAdapterInitAsync Failed"); DEBUG_ERROR_HR(status, "IddCxAdapterInitAsync Failed");
return; return;
} }
@ -161,7 +161,7 @@ void CIndirectDeviceContext::FinishInit(UINT connectorIndex)
NTSTATUS status = IddCxMonitorCreate(m_adapter, &create, &createOut); NTSTATUS status = IddCxMonitorCreate(m_adapter, &create, &createOut);
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
DBGPRINT("IddCxMonitorCreate Failed"); DEBUG_ERROR_HR(status, "IddCxMonitorCreate Failed");
return; return;
} }
@ -198,7 +198,7 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
KVMFRRecord_VMInfo * vmInfo = static_cast<KVMFRRecord_VMInfo *>(calloc(1, sizeof(*vmInfo))); KVMFRRecord_VMInfo * vmInfo = static_cast<KVMFRRecord_VMInfo *>(calloc(1, sizeof(*vmInfo)));
if (!vmInfo) if (!vmInfo)
{ {
DBGPRINT("Failed to allocate KVMFRRecord_VMInfo"); DEBUG_ERROR("Failed to allocate KVMFRRecord_VMInfo");
return false; return false;
} }
vmInfo->cpus = static_cast<uint8_t>(CPlatformInfo::GetProcCount ()); vmInfo->cpus = static_cast<uint8_t>(CPlatformInfo::GetProcCount ());
@ -212,7 +212,7 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
KVMFRRecord * record = static_cast<KVMFRRecord *>(calloc(1, sizeof(*record))); KVMFRRecord * record = static_cast<KVMFRRecord *>(calloc(1, sizeof(*record)));
if (!record) if (!record)
{ {
DBGPRINT("Failed to allocate KVMFRRecord"); DEBUG_ERROR("Failed to allocate KVMFRRecord");
return false; return false;
} }
@ -228,7 +228,7 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
KVMFRRecord_OSInfo * osInfo = static_cast<KVMFRRecord_OSInfo *>(calloc(1, sizeof(*osInfo))); KVMFRRecord_OSInfo * osInfo = static_cast<KVMFRRecord_OSInfo *>(calloc(1, sizeof(*osInfo)));
if (!osInfo) if (!osInfo)
{ {
DBGPRINT("Failed to allocate KVMFRRecord_OSInfo"); DEBUG_ERROR("Failed to allocate KVMFRRecord_OSInfo");
return false; return false;
} }
@ -239,7 +239,7 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
KVMFRRecord* record = static_cast<KVMFRRecord*>(calloc(1, sizeof(*record))); KVMFRRecord* record = static_cast<KVMFRRecord*>(calloc(1, sizeof(*record)));
if (!record) if (!record)
{ {
DBGPRINT("Failed to allocate KVMFRRecord"); DEBUG_ERROR("Failed to allocate KVMFRRecord");
return false; return false;
} }
@ -257,19 +257,19 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
if ((status = lgmpHostInit(m_ivshmem.GetMem(), (uint32_t)m_ivshmem.GetSize(), if ((status = lgmpHostInit(m_ivshmem.GetMem(), (uint32_t)m_ivshmem.GetSize(),
&m_lgmp, (uint32_t)udata.size(), (uint8_t*)&udata[0])) != LGMP_OK) &m_lgmp, (uint32_t)udata.size(), (uint8_t*)&udata[0])) != LGMP_OK)
{ {
DBGPRINT("lgmpHostInit Failed: %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostInit Failed: %s", lgmpStatusString(status));
return false; return false;
} }
if ((status = lgmpHostQueueNew(m_lgmp, FRAME_QUEUE_CONFIG, &m_frameQueue)) != LGMP_OK) if ((status = lgmpHostQueueNew(m_lgmp, FRAME_QUEUE_CONFIG, &m_frameQueue)) != LGMP_OK)
{ {
DBGPRINT("lgmpHostQueueCreate Failed (Frame): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostQueueCreate Failed (Frame): %s", lgmpStatusString(status));
return false; return false;
} }
if ((status = lgmpHostQueueNew(m_lgmp, POINTER_QUEUE_CONFIG, &m_pointerQueue)) != LGMP_OK) if ((status = lgmpHostQueueNew(m_lgmp, POINTER_QUEUE_CONFIG, &m_pointerQueue)) != LGMP_OK)
{ {
DBGPRINT("lgmpHostQueueCreate Failed (Pointer): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostQueueCreate Failed (Pointer): %s", lgmpStatusString(status));
return false; return false;
} }
@ -277,7 +277,7 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
{ {
if ((status = lgmpHostMemAlloc(m_lgmp, MAX_POINTER_SIZE, &m_pointerMemory[i])) != LGMP_OK) if ((status = lgmpHostMemAlloc(m_lgmp, MAX_POINTER_SIZE, &m_pointerMemory[i])) != LGMP_OK)
{ {
DBGPRINT("lgmpHostMemAlloc Failed (Pointer): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer): %s", lgmpStatusString(status));
return false; return false;
} }
memset(lgmpHostMemPtr(m_pointerMemory[i]), 0, MAX_POINTER_SIZE); memset(lgmpHostMemPtr(m_pointerMemory[i]), 0, MAX_POINTER_SIZE);
@ -287,7 +287,7 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
{ {
if ((status = lgmpHostMemAlloc(m_lgmp, MAX_POINTER_SIZE, &m_pointerShapeMemory[i])) != LGMP_OK) if ((status = lgmpHostMemAlloc(m_lgmp, MAX_POINTER_SIZE, &m_pointerShapeMemory[i])) != LGMP_OK)
{ {
DBGPRINT("lgmpHostMemAlloc Failed (Pointer Shapes): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer Shapes): %s", lgmpStatusString(status));
return false; return false;
} }
memset(lgmpHostMemPtr(m_pointerShapeMemory[i]), 0, MAX_POINTER_SIZE); memset(lgmpHostMemPtr(m_pointerShapeMemory[i]), 0, MAX_POINTER_SIZE);
@ -296,13 +296,13 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
m_maxFrameSize = lgmpHostMemAvail(m_lgmp); m_maxFrameSize = lgmpHostMemAvail(m_lgmp);
m_maxFrameSize = (m_maxFrameSize -(m_alignSize - 1)) & ~(m_alignSize - 1); m_maxFrameSize = (m_maxFrameSize -(m_alignSize - 1)) & ~(m_alignSize - 1);
m_maxFrameSize /= LGMP_Q_FRAME_LEN; m_maxFrameSize /= LGMP_Q_FRAME_LEN;
DBGPRINT("Max Frame Size: %u MiB", (unsigned int)(m_maxFrameSize / 1048576LL)); DEBUG_INFO("Max Frame Size: %u MiB", (unsigned int)(m_maxFrameSize / 1048576LL));
for (int i = 0; i < LGMP_Q_FRAME_LEN; ++i) for (int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
if ((status = lgmpHostMemAllocAligned(m_lgmp, (uint32_t)m_maxFrameSize, if ((status = lgmpHostMemAllocAligned(m_lgmp, (uint32_t)m_maxFrameSize,
(uint32_t)m_alignSize, &m_frameMemory[i])) != LGMP_OK) (uint32_t)m_alignSize, &m_frameMemory[i])) != LGMP_OK)
{ {
DBGPRINT("lgmpHostMemAllocAligned Failed (Frame): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostMemAllocAligned Failed (Frame): %s", lgmpStatusString(status));
return false; return false;
} }
@ -329,7 +329,7 @@ bool CIndirectDeviceContext::SetupLGMP(size_t alignSize)
NTSTATUS s = WdfTimerCreate(&config, &attribs, &m_lgmpTimer); NTSTATUS s = WdfTimerCreate(&config, &attribs, &m_lgmpTimer);
if (!NT_SUCCESS(s)) if (!NT_SUCCESS(s))
{ {
DBGPRINT("Timer creation failed: 0x%08x", s); DEBUG_ERROR_HR(s, "Timer creation failed");
return false; return false;
} }
WdfTimerStart(m_lgmpTimer, WDF_REL_TIMEOUT_IN_MS(10)); WdfTimerStart(m_lgmpTimer, WDF_REL_TIMEOUT_IN_MS(10));
@ -364,12 +364,12 @@ void CIndirectDeviceContext::LGMPTimer()
{ {
if (status == LGMP_ERR_CORRUPTED) if (status == LGMP_ERR_CORRUPTED)
{ {
DBGPRINT("LGMP reported the shared memory has been corrupted, attempting to recover\n"); DEBUG_WARN("LGMP reported the shared memory has been corrupted, attempting to recover\n");
//TODO: fixme - reinit //TODO: fixme - reinit
return; return;
} }
DBGPRINT("lgmpHostProcess Failed: %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostProcess Failed: %s", lgmpStatusString(status));
//TODO: fixme - shutdown //TODO: fixme - shutdown
return; return;
} }
@ -451,7 +451,7 @@ CIndirectDeviceContext::PreparedFrameBuffer CIndirectDeviceContext::PrepareFrame
break; break;
default: default:
DBGPRINT("Unsuppoted DXGI format"); DEBUG_ERROR("Unsuppoted DXGI format 0x%08x", format);
return result; return result;
} }
@ -556,7 +556,7 @@ void CIndirectDeviceContext::SendCursor(const IDARG_OUT_QUERY_HWCURSOR& info, co
continue; continue;
} }
DBGPRINT("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status));
break; break;
} }
} }
@ -584,7 +584,7 @@ void CIndirectDeviceContext::ResendCursor()
continue; continue;
} }
DBGPRINT("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status)); DEBUG_ERROR("lgmpHostQueuePost Failed (Pointer): %s", lgmpStatusString(status));
break; break;
} }
} }

View File

@ -59,7 +59,7 @@ void CIndirectMonitorContext::AssignSwapChain(IDDCX_SWAPCHAIN swapChain, LUID re
if (!m_devContext->SetupLGMP(alignSize)) if (!m_devContext->SetupLGMP(alignSize))
{ {
WdfObjectDelete(swapChain); WdfObjectDelete(swapChain);
DBGPRINT("SetupLGMP failed"); DEBUG_ERROR("SetupLGMP failed");
return; return;
} }
@ -74,7 +74,7 @@ void CIndirectMonitorContext::AssignSwapChain(IDDCX_SWAPCHAIN swapChain, LUID re
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
WdfObjectDelete(swapChain); WdfObjectDelete(swapChain);
DBGPRINT("IddCxMonitorSetupHardwareCursor Failed: %08x", status); DEBUG_ERROR_HR(status, "IddCxMonitorSetupHardwareCursor Failed");
return; return;
} }
@ -114,7 +114,7 @@ void CIndirectMonitorContext::CursorThread()
else if (waitResult != WAIT_OBJECT_0) else if (waitResult != WAIT_OBJECT_0)
{ {
hr = HRESULT_FROM_WIN32(waitResult); hr = HRESULT_FROM_WIN32(waitResult);
DBGPRINT("WaitForMultipleObjects: %08", hr); DEBUG_ERROR_HR(hr, "WaitForMultipleObjects");
return; return;
} }
@ -127,7 +127,7 @@ void CIndirectMonitorContext::CursorThread()
NTSTATUS status = IddCxMonitorQueryHardwareCursor(m_monitor, &in, &out); NTSTATUS status = IddCxMonitorQueryHardwareCursor(m_monitor, &in, &out);
if (FAILED(status)) if (FAILED(status))
{ {
DBGPRINT("IddCxMonitorQueryHardwareCursor failed: %08x", status); DEBUG_ERROR_HR(status, "IddCxMonitorQueryHardwareCursor failed");
return; return;
} }

View File

@ -12,7 +12,7 @@ bool CInteropResource::Init(std::shared_ptr<CD3D11Device> dx11Device, std::share
hr = srcTex.As(&rSrcTex); hr = srcTex.As(&rSrcTex);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to obtain the IDXGIResource1 interface"); DEBUG_ERROR_HR(hr, "Failed to obtain the IDXGIResource1 interface");
return false; return false;
} }
@ -21,7 +21,7 @@ bool CInteropResource::Init(std::shared_ptr<CD3D11Device> dx11Device, std::share
hr = rSrcTex->CreateSharedHandle(NULL, DXGI_SHARED_RESOURCE_READ, NULL, &h); hr = rSrcTex->CreateSharedHandle(NULL, DXGI_SHARED_RESOURCE_READ, NULL, &h);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the shared handle"); DEBUG_ERROR_HR(hr, "Failed to create the shared handle");
return false; return false;
} }
sharedHandle.Attach(h); sharedHandle.Attach(h);
@ -30,7 +30,7 @@ bool CInteropResource::Init(std::shared_ptr<CD3D11Device> dx11Device, std::share
hr = dx12Device->GetDevice()->OpenSharedHandle(sharedHandle.Get(), IID_PPV_ARGS(&dst)); hr = dx12Device->GetDevice()->OpenSharedHandle(sharedHandle.Get(), IID_PPV_ARGS(&dst));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to open the D3D12Resource from the handle"); DEBUG_ERROR_HR(hr, "Failed to open the D3D12Resource from the handle");
return false; return false;
} }
@ -40,14 +40,14 @@ bool CInteropResource::Init(std::shared_ptr<CD3D11Device> dx11Device, std::share
hr = dx11Device->GetDevice()->CreateFence(0, D3D11_FENCE_FLAG_SHARED, IID_PPV_ARGS(&d11Fence)); hr = dx11Device->GetDevice()->CreateFence(0, D3D11_FENCE_FLAG_SHARED, IID_PPV_ARGS(&d11Fence));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the d3d11 fence"); DEBUG_ERROR_HR(hr, "Failed to create the d3d11 fence");
return false; return false;
} }
hr = d11Fence->CreateSharedHandle(NULL, GENERIC_ALL, NULL, &h); hr = d11Fence->CreateSharedHandle(NULL, GENERIC_ALL, NULL, &h);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to create the d3d11 fence shared handle"); DEBUG_ERROR_HR(hr, "Failed to create the d3d11 fence shared handle");
return false; return false;
} }
sharedHandle.Attach(h); sharedHandle.Attach(h);
@ -56,7 +56,7 @@ bool CInteropResource::Init(std::shared_ptr<CD3D11Device> dx11Device, std::share
hr = dx12Device->GetDevice()->OpenSharedHandle(sharedHandle.Get(), IID_PPV_ARGS(&d12Fence)); hr = dx12Device->GetDevice()->OpenSharedHandle(sharedHandle.Get(), IID_PPV_ARGS(&d12Fence));
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to open the D3D12Fence from the handle"); DEBUG_ERROR_HR(hr, "Failed to open the D3D12Fence from the handle");
return false; return false;
} }

View File

@ -35,7 +35,7 @@ CInteropResource* CInteropResourcePool::Get(ComPtr<ID3D11Texture2D> srcTex)
if (freeSlot == POOL_SIZE) if (freeSlot == POOL_SIZE)
{ {
DBGPRINT("Interop Resouce Pool Full"); DEBUG_ERROR("Interop Resouce Pool Full");
return nullptr; return nullptr;
} }

View File

@ -60,7 +60,7 @@ void CPlatformInfo::Init()
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
m_productName = "Unknown"; m_productName = "Unknown";
DBGPRINT("Failed to read the ProductName"); DEBUG_ERROR("Failed to read the ProductName");
} }
else else
m_productName.resize(bufferSize - 1); // remove the double null termination m_productName.resize(bufferSize - 1); // remove the double null termination
@ -167,14 +167,14 @@ void CPlatformInfo::InitUUID()
smbData = (RawSMBIOSData*)new BYTE[smbDataSize]; smbData = (RawSMBIOSData*)new BYTE[smbDataSize];
if (!smbData) if (!smbData)
{ {
DBGPRINT("out of memory"); DEBUG_ERROR("out of memory");
return; return;
} }
if (GetSystemFirmwareTable(TABLE_SIG("RSMB"), 0, smbData, smbDataSize) if (GetSystemFirmwareTable(TABLE_SIG("RSMB"), 0, smbData, smbDataSize)
!= smbDataSize) != smbDataSize)
{ {
DBGPRINT("Failed to read the RSMB table"); DEBUG_ERROR("Failed to read the RSMB table");
delete[] smbData; delete[] smbData;
return; return;
} }
@ -220,7 +220,7 @@ void CPlatformInfo::InitCPUInfo()
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
m_model = "Unknown"; m_model = "Unknown";
DBGPRINT("Failed to read the CPU Model"); DEBUG_ERROR("Failed to read the CPU Model");
} }
else else
{ {
@ -233,20 +233,20 @@ void CPlatformInfo::InitCPUInfo()
GetLogicalProcessorInformationEx(RelationAll, nullptr, &cb); GetLogicalProcessorInformationEx(RelationAll, nullptr, &cb);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{ {
DBGPRINT("Failed to call GetLogicalProcessorInformationEx"); DEBUG_ERROR("Failed to call GetLogicalProcessorInformationEx");
return; return;
} }
BYTE * buffer = static_cast<BYTE *>(_malloca(cb)); BYTE * buffer = static_cast<BYTE *>(_malloca(cb));
if (!buffer) if (!buffer)
{ {
DBGPRINT("Failed to allocate buffer for processor information"); DEBUG_ERROR("Failed to allocate buffer for processor information");
return; return;
} }
if (!GetLogicalProcessorInformationEx(RelationAll, if (!GetLogicalProcessorInformationEx(RelationAll,
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)buffer, &cb)) (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)buffer, &cb))
{ {
DBGPRINT("Failed to call GetLogicalProcessorInformationEx"); DEBUG_ERROR("Failed to call GetLogicalProcessorInformationEx");
_freea(buffer); _freea(buffer);
return; return;
} }

View File

@ -72,7 +72,7 @@ void CSwapChainProcessor::SwapChainThread()
DWORD avTask = 0; DWORD avTask = 0;
HANDLE avTaskHandle = AvSetMmThreadCharacteristicsW(L"Distribution", &avTask); HANDLE avTaskHandle = AvSetMmThreadCharacteristicsW(L"Distribution", &avTask);
DBGPRINT("Start"); DEBUG_INFO("Start Thread");
SwapChainThreadCore(); SwapChainThreadCore();
WdfObjectDelete((WDFOBJECT)m_hSwapChain); WdfObjectDelete((WDFOBJECT)m_hSwapChain);
@ -87,21 +87,22 @@ void CSwapChainProcessor::SwapChainThreadCore()
HRESULT hr = m_dx11Device->GetDevice().As(&dxgiDevice); HRESULT hr = m_dx11Device->GetDevice().As(&dxgiDevice);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT("Failed to get the dxgiDevice"); DEBUG_ERROR_HR(hr, "Failed to get the dxgiDevice");
return; return;
} }
if (IDD_IS_FUNCTION_AVAILABLE(IddCxSetRealtimeGPUPriority)) if (IDD_IS_FUNCTION_AVAILABLE(IddCxSetRealtimeGPUPriority))
{ {
DBGPRINT("Using IddCxSetRealtimeGPUPriority"); DEBUG_INFO("Using IddCxSetRealtimeGPUPriority");
IDARG_IN_SETREALTIMEGPUPRIORITY arg; IDARG_IN_SETREALTIMEGPUPRIORITY arg;
arg.pDevice = dxgiDevice.Get(); arg.pDevice = dxgiDevice.Get();
if (FAILED(IddCxSetRealtimeGPUPriority(m_hSwapChain, &arg))) hr = IddCxSetRealtimeGPUPriority(m_hSwapChain, &arg);
DBGPRINT("Failed to set realtime GPU thread priority"); if (FAILED(hr))
DEBUG_ERROR_HR(hr, "Failed to set realtime GPU thread priority");
} }
else else
{ {
DBGPRINT("Using SetGPUThreadPriority"); DEBUG_INFO("Using SetGPUThreadPriority");
dxgiDevice->SetGPUThreadPriority(7); dxgiDevice->SetGPUThreadPriority(7);
} }
@ -111,7 +112,7 @@ void CSwapChainProcessor::SwapChainThreadCore()
hr = IddCxSwapChainSetDevice(m_hSwapChain, &setDevice); hr = IddCxSwapChainSetDevice(m_hSwapChain, &setDevice);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "IddCxSwapChainSetDevice Failed"); DEBUG_ERROR_HR(hr, "IddCxSwapChainSetDevice Failed");
return; return;
} }
@ -164,14 +165,14 @@ void CSwapChainProcessor::SwapChainNewFrame(ComPtr<IDXGIResource> acquiredBuffer
HRESULT hr = acquiredBuffer.As(&texture); HRESULT hr = acquiredBuffer.As(&texture);
if (FAILED(hr)) if (FAILED(hr))
{ {
DBGPRINT_HR(hr, "Failed to obtain the ID3D11Texture2D from the acquiredBuffer"); DEBUG_ERROR_HR(hr, "Failed to obtain the ID3D11Texture2D from the acquiredBuffer");
return; return;
} }
CInteropResource * srcRes = m_resPool.Get(texture); CInteropResource * srcRes = m_resPool.Get(texture);
if (!srcRes) if (!srcRes)
{ {
DBGPRINT("Failed to get a CInteropResource from the pool"); DEBUG_ERROR("Failed to get a CInteropResource from the pool");
return; return;
} }
@ -199,7 +200,7 @@ void CSwapChainProcessor::SwapChainNewFrame(ComPtr<IDXGIResource> acquiredBuffer
if (!fbRes) if (!fbRes)
{ {
DBGPRINT("Failed to get a CFrameBufferResource from the pool"); DEBUG_ERROR("Failed to get a CFrameBufferResource from the pool");
return; return;
} }

View File

@ -159,10 +159,10 @@ NTSTATUS LGIddCreateDevice(_Inout_ PWDFDEVICE_INIT deviceInit)
status = IddCxGetVersion(&ver); status = IddCxGetVersion(&ver);
if (FAILED(status)) if (FAILED(status))
{ {
DBGPRINT("IddCxGetVersion Failed"); DEBUG_ERROR("IddCxGetVersion Failed");
return status; return status;
} }
DBGPRINT("Version: 0x%04x", ver.IddCxVersion); DEBUG_INFO("Version: 0x%04x", ver.IddCxVersion);
WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);