Skip to content

Commit 4691634

Browse files
committed
Improve logging and some errors
1 parent aefce37 commit 4691634

File tree

4 files changed

+68
-8
lines changed

4 files changed

+68
-8
lines changed

src/rendering/openxr.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ OpenXR::OpenXR() {
1111
xrEnumerateInstanceExtensionProperties(NULL, 0, &xrExtensionCount, NULL);
1212
std::vector<XrExtensionProperties> instanceExtensions;
1313
instanceExtensions.resize(xrExtensionCount, { XR_TYPE_EXTENSION_PROPERTIES, NULL });
14-
checkXRResult(xrEnumerateInstanceExtensionProperties(NULL, xrExtensionCount, &xrExtensionCount, instanceExtensions.data()), "Couldn't enumerate OpenXR extensions!");
14+
{
15+
XrResult result = xrEnumerateInstanceExtensionProperties(NULL, xrExtensionCount, &xrExtensionCount, instanceExtensions.data());
16+
if (result == XR_ERROR_RUNTIME_FAILURE) {
17+
Log::print<ERROR>("Couldn't enumerate OpenXR extensions! Is the OpenXR runtime installed and set to the correct runtime? Restarting might help, or going to SteamVR/Oculus Link's Settings and making sure OpenXR is enabled.");
18+
}
19+
checkXRResult(result, "Couldn't enumerate OpenXR extensions!");
20+
}
1521

1622
// Create instance with required extensions
1723
bool d3d12Supported = false;
@@ -63,7 +69,13 @@ OpenXR::OpenXR() {
6369
xrInstanceCreateInfo.enabledApiLayerCount = 0;
6470
xrInstanceCreateInfo.enabledApiLayerNames = NULL;
6571
xrInstanceCreateInfo.applicationInfo = { "BetterVR", 1, "Cemu", 1, XR_API_VERSION_1_0 };
66-
checkXRResult(xrCreateInstance(&xrInstanceCreateInfo, &m_instance), "Failed to initialize the OpenXR instance!");
72+
{
73+
XrResult result = xrCreateInstance(&xrInstanceCreateInfo, &m_instance);
74+
if (result == XR_ERROR_RUNTIME_FAILURE) {
75+
Log::print<ERROR>("Failed to create OpenXR instance! Is the OpenXR runtime installed and set to the correct runtime? Restarting might help, or going to SteamVR/Oculus Link's Settings and making sure OpenXR is enabled.");
76+
}
77+
checkXRResult(result, "Failed to initialize the OpenXR instance!");
78+
}
6779

6880
// Load extension pointers for this XrInstance
6981
xrGetInstanceProcAddr(m_instance, "xrGetD3D12GraphicsRequirementsKHR", (PFN_xrVoidFunction*)&func_xrGetD3D12GraphicsRequirementsKHR);

src/rendering/vulkan.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ RND_Vulkan::RND_Vulkan(VkInstance vkInstance, VkPhysicalDevice vkPhysDevice, VkD
88
m_deviceDispatch = vkroots::tables::LookupDeviceDispatch(vkDevice);
99

1010
m_physicalDeviceDispatch->GetPhysicalDeviceMemoryProperties2KHR(vkPhysDevice, &m_memoryProperties);
11+
12+
VkPhysicalDeviceProperties props{};
13+
m_instanceDispatch->GetPhysicalDeviceProperties(vkPhysDevice, &props);
14+
15+
uint64_t localVramBytes = 0;
16+
for (uint32_t i = 0; i < m_memoryProperties.memoryProperties.memoryHeapCount; ++i) {
17+
if ((m_memoryProperties.memoryProperties.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) {
18+
localVramBytes += m_memoryProperties.memoryProperties.memoryHeaps[i].size;
19+
}
20+
}
21+
22+
Log::print<INFO>("GPU: {} (vendor={:#06x}, device={:#06x}, driver={})", props.deviceName, props.vendorID, props.deviceID, props.driverVersion);
23+
if (localVramBytes > 0) {
24+
Log::print<INFO>("GPU VRAM (device local): {:.2f} GiB", double(localVramBytes) / (1024.0 * 1024.0 * 1024.0));
25+
}
1126
}
1227

1328
RND_Vulkan::~RND_Vulkan() {

src/utils/logger.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1+
#include "logger.h"
2+
13
HANDLE Log::consoleHandle = NULL;
24
double Log::timeFrequency = 0.0f;
35
std::ofstream Log::logFile;
6+
std::mutex Log::logMutex;
7+
8+
static void LogSystemHardwareInfo() {
9+
int cpuInfo[4] = {0, 0, 0, 0};
10+
__cpuid(cpuInfo, 0x80000000);
11+
const unsigned int maxExId = static_cast<unsigned int>(cpuInfo[0]);
12+
13+
std::string cpuBrand;
14+
if (maxExId >= 0x80000004) {
15+
char brand[49] = {};
16+
__cpuid(reinterpret_cast<int*>(brand + 0), 0x80000002);
17+
__cpuid(reinterpret_cast<int*>(brand + 16), 0x80000003);
18+
__cpuid(reinterpret_cast<int*>(brand + 32), 0x80000004);
19+
cpuBrand = brand;
20+
while (!cpuBrand.empty() && cpuBrand.front() == ' ') cpuBrand.erase(cpuBrand.begin());
21+
while (!cpuBrand.empty() && cpuBrand.back() == ' ') cpuBrand.pop_back();
22+
if (!cpuBrand.empty()) {
23+
Log::print<INFO>("CPU: {}", cpuBrand.c_str());
24+
}
25+
}
26+
27+
MEMORYSTATUSEX statex{};
28+
statex.dwLength = sizeof(statex);
29+
if (GlobalMemoryStatusEx(&statex)) {
30+
const double totalGiB = double(statex.ullTotalPhys) / (1024.0 * 1024.0 * 1024.0);
31+
Log::print<INFO>("RAM: {:.2f} GiB", totalGiB);
32+
}
33+
}
434

535
Log::Log() {
636
AllocConsole();
737
SetConsoleTitleA("BetterVR Debugging Console");
838
consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
9-
#ifdef _DEBUG
10-
#else
11-
logFile.open("BetterVR.txt", std::ios::out | std::ios::trunc);
39+
#ifndef _DEBUG
40+
logFile.open("BetterVR_log.txt", std::ios::out | std::ios::trunc);
1241
#endif
1342
Log::print<INFO>("Successfully started BetterVR!");
43+
LogSystemHardwareInfo();
44+
1445
LARGE_INTEGER timeLI;
1546
QueryPerformanceFrequency(&timeLI);
1647
timeFrequency = double(timeLI.QuadPart) / 1000.0;
@@ -19,8 +50,7 @@ Log::Log() {
1950
Log::~Log() {
2051
Log::print<INFO>("Shutting down BetterVR debugging console...");
2152
FreeConsole();
22-
#ifdef _DEBUG
23-
#else
53+
#ifndef _DEBUG
2454
if (logFile.is_open()) {
2555
logFile.close();
2656
}

src/utils/logger.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma once
12
#include "vkroots.h"
23
#include <fstream>
34

@@ -255,8 +256,9 @@ class Log {
255256
if constexpr (!isLogTypeEnabled<L>()) {
256257
return;
257258
}
259+
std::lock_guard<std::mutex> lock(logMutex);
258260
std::string messageStr = std::string(message) + "\n";
259-
261+
260262
#ifndef _DEBUG
261263
if (logFile.is_open()) {
262264
logFile << messageStr;
@@ -290,6 +292,7 @@ class Log {
290292
static HANDLE consoleHandle;
291293
static double timeFrequency;
292294
static std::ofstream logFile;
295+
static std::mutex logMutex;
293296
};
294297

295298
static void checkXRResult(const XrResult result, const char* errorMessage) {

0 commit comments

Comments
 (0)