添加调试日志

This commit is contained in:
xsl
2026-04-23 11:29:18 +08:00
parent 7ab4274e4f
commit fb434f09b8
8 changed files with 477 additions and 3 deletions
+61 -2
View File
@@ -9,8 +9,47 @@
#include <game-activity/GameActivity.h>
#include <vulkan/vulkan_android.h>
#include "../app/src/main/cpp/AndroidOut.h"
#include "../app/src/main/cpp/DebugLog.h"
#endif
#ifdef _WIN32
#define FACE_DBG_LOG(...) ((void)0)
#else
#define FACE_DBG_LOG(...) DebugLog::log(__VA_ARGS__)
#endif
static const char* VkResultStr(VkResult r) {
switch (r) {
case VK_SUCCESS: return "VK_SUCCESS";
case VK_NOT_READY: return "VK_NOT_READY";
case VK_TIMEOUT: return "VK_TIMEOUT";
case VK_EVENT_SET: return "VK_EVENT_SET";
case VK_EVENT_RESET: return "VK_EVENT_RESET";
case VK_INCOMPLETE: return "VK_INCOMPLETE";
case VK_SUBOPTIMAL_KHR: return "VK_SUBOPTIMAL_KHR";
case VK_ERROR_OUT_OF_HOST_MEMORY: return "VK_ERROR_OUT_OF_HOST_MEMORY";
case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
case VK_ERROR_INITIALIZATION_FAILED: return "VK_ERROR_INITIALIZATION_FAILED";
case VK_ERROR_DEVICE_LOST: return "VK_ERROR_DEVICE_LOST";
case VK_ERROR_MEMORY_MAP_FAILED: return "VK_ERROR_MEMORY_MAP_FAILED";
case VK_ERROR_LAYER_NOT_PRESENT: return "VK_ERROR_LAYER_NOT_PRESENT";
case VK_ERROR_EXTENSION_NOT_PRESENT: return "VK_ERROR_EXTENSION_NOT_PRESENT";
case VK_ERROR_FEATURE_NOT_PRESENT: return "VK_ERROR_FEATURE_NOT_PRESENT";
case VK_ERROR_INCOMPATIBLE_DRIVER: return "VK_ERROR_INCOMPATIBLE_DRIVER";
case VK_ERROR_TOO_MANY_OBJECTS: return "VK_ERROR_TOO_MANY_OBJECTS";
case VK_ERROR_FORMAT_NOT_SUPPORTED: return "VK_ERROR_FORMAT_NOT_SUPPORTED";
case VK_ERROR_FRAGMENTED_POOL: return "VK_ERROR_FRAGMENTED_POOL";
case VK_ERROR_OUT_OF_DATE_KHR: return "VK_ERROR_OUT_OF_DATE_KHR";
case VK_ERROR_SURFACE_LOST_KHR: return "VK_ERROR_SURFACE_LOST_KHR";
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
case VK_ERROR_OUT_OF_POOL_MEMORY: return "VK_ERROR_OUT_OF_POOL_MEMORY";
case VK_ERROR_INVALID_EXTERNAL_HANDLE: return "VK_ERROR_INVALID_EXTERNAL_HANDLE";
case VK_ERROR_FRAGMENTATION: return "VK_ERROR_FRAGMENTATION";
case VK_ERROR_UNKNOWN: return "VK_ERROR_UNKNOWN";
default: return "VK_UNMAPPED_VALUE";
}
}
void Application::initWindow()
@@ -545,13 +584,24 @@ void Application::render(VkCommandBuffer commandBuffer, long long frameTime)
void Application::drawFrame(long long frameTime)
{
static uint64_t s_drawFrameCount = 0;
++s_drawFrameCount;
// 1. 等待前一帧完成
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
VkResult waitRes = vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
if (waitRes != VK_SUCCESS) {
FACE_DBG_LOG("drawFrame[%llu] vkWaitForFences -> %d (%s) currentFrame=%u",
(unsigned long long)s_drawFrameCount,
(int)waitRes, VkResultStr(waitRes), currentFrame);
}
// 2. 获取交换链图像
uint32_t imageIndex;
VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
if (result != VK_SUCCESS) {
FACE_DBG_LOG("drawFrame[%llu] vkAcquireNextImageKHR -> %d (%s) currentFrame=%u",
(unsigned long long)s_drawFrameCount,
(int)result, VkResultStr(result), currentFrame);
throw std::runtime_error("failed to acquire swap chain image!");
}
@@ -582,7 +632,12 @@ void Application::drawFrame(long long frameTime)
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores;
if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) {
VkResult submitRes = vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]);
if (submitRes != VK_SUCCESS) {
FACE_DBG_LOG("drawFrame[%llu] vkQueueSubmit -> %d (%s) currentFrame=%u imageIndex=%u",
(unsigned long long)s_drawFrameCount,
(int)submitRes, VkResultStr(submitRes),
currentFrame, imageIndex);
throw std::runtime_error("failed to submit draw command buffer!");
}
// 7. 呈现图像
@@ -597,6 +652,10 @@ void Application::drawFrame(long long frameTime)
result = vkQueuePresentKHR(presentQueue, &presentInfo);
if (result != VK_SUCCESS) {
FACE_DBG_LOG("drawFrame[%llu] vkQueuePresentKHR -> %d (%s) currentFrame=%u imageIndex=%u",
(unsigned long long)s_drawFrameCount,
(int)result, VkResultStr(result),
currentFrame, imageIndex);
throw std::runtime_error("failed to present swap chain image!");
}