You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(vulkan): enhance device recovery and logging mechanisms
- Implemented additional logging for device recovery attempts and outcomes, providing clearer diagnostics during Vulkan rendering.
- Updated the handling of device loss scenarios to ensure graceful recovery attempts and prevent application crashes.
- Improved VRAM statistics management with bounds checking to prevent overflow and underflow issues during memory allocation and deallocation.
- Added checks to skip pipeline creation and rendering operations when the device is lost, enhancing stability and performance.
// Test if device is responsive by trying to recreate swapchain
434
-
if (vk.device!=VK_NULL_HANDLE&&vk.physical_device!=VK_NULL_HANDLE&&vk.swapchain!=VK_NULL_HANDLE) {
440
+
// Handle both cases: swapchain exists or needs to be created
441
+
if (vk.device!=VK_NULL_HANDLE&&vk.physical_device!=VK_NULL_HANDLE) {
435
442
// Temporarily clear device_lost flag to allow swapchain operations
436
443
qbooleanwas_device_lost=vk.device_lost;
437
444
vk.device_lost=qfalse;
438
445
439
-
// Try recreating swapchain - this will fail if device is still lost
440
-
ri.Printf(PRINT_ALL, "Vulkan: Attempting swapchain recreation to test device recovery...\n");
441
-
vk_recreate_swapchain();
446
+
// If swapchain doesn't exist, try to create it; otherwise recreate it
447
+
VkResultswapchain_result=VK_SUCCESS;
448
+
if (vk.swapchain==VK_NULL_HANDLE) {
449
+
ri.Printf(PRINT_ALL, "Vulkan: Swapchain missing, attempting to create it for recovery...\n");
450
+
// Try to create swapchain - this requires surface to exist
451
+
if (vk.surface!=VK_NULL_HANDLE) {
452
+
// Use safe version that returns error code instead of calling ri.Error
453
+
swapchain_result=vk_recreate_swapchain_safe();
454
+
} else {
455
+
ri.Printf(PRINT_WARNING, "Vulkan: Cannot create swapchain - surface not available. Will retry in 5 seconds.\n");
456
+
vk.device_lost=was_device_lost; // Restore flag
457
+
swapchain_result=VK_ERROR_SURFACE_LOST_KHR; // Mark as failed
458
+
}
459
+
} else {
460
+
// Try recreating existing swapchain - this will fail if device is still lost
461
+
ri.Printf(PRINT_ALL, "Vulkan: Attempting swapchain recreation to test device recovery...\n");
462
+
swapchain_result=vk_recreate_swapchain_safe();
463
+
}
464
+
465
+
// Handle swapchain recreation errors gracefully
466
+
if (swapchain_result!=VK_SUCCESS) {
467
+
if (swapchain_result==VK_ERROR_OUT_OF_DEVICE_MEMORY) {
468
+
ri.Printf(PRINT_WARNING, "Vulkan: Swapchain recreation failed - OUT_OF_DEVICE_MEMORY. GPU driver may need more time to recover. Will retry in 10 seconds.\n");
469
+
// Increase retry interval for out-of-memory errors
470
+
last_recovery_attempt=current_time-5000; // Allow retry in 10 seconds instead of 5
471
+
} else {
472
+
ri.Printf(PRINT_WARNING, "Vulkan: Swapchain recreation failed: %s. Will retry in 5 seconds.\n", vk_result_string(swapchain_result));
473
+
}
474
+
vk.device_lost=was_device_lost; // Restore flag
475
+
}
442
476
443
-
// Test if swapchain recreation succeeded by trying to acquire an image
477
+
// Test if swapchain creation/recreation succeeded by trying to acquire an image
444
478
if (qvkAcquireNextImageKHR&&vk.swapchain!=VK_NULL_HANDLE) {
ri.Printf(PRINT_WARNING, "Failed to create Vulkan depth fragment pipeline for shader stage\n");
4126
4151
// Don't fail, depth fragment pipeline is optional
4127
4152
}
4153
+
// Check if device was lost during pipeline creation
4154
+
if (vk.device_lost) {
4155
+
ri.Printf(PRINT_WARNING, "Vulkan: Device lost during depth fragment pipeline creation for shader %s, skipping remaining pipeline creation\n", shader.name);
// Check if device was lost during mirror pipeline creation
4162
+
if (vk.device_lost) {
4163
+
ri.Printf(PRINT_WARNING, "Vulkan: Device lost during mirror depth fragment pipeline creation for shader %s, skipping remaining pipeline creation\n", shader.name);
4164
+
break; // Exit the stage loop
4165
+
}
4131
4166
ri.Printf(PRINT_ALL, "DEBUG: Depth fragment mirror pipeline call completed\n");
4132
4167
if (pStage->vk_mirror_pipeline_df==VK_NULL_HANDLE) {
4133
4168
ri.Printf(PRINT_WARNING, "Failed to create Vulkan mirror depth fragment pipeline for shader stage\n");
ri.Error(ERR_FATAL, "Vulkan device lost (%s) at %s:%d - This usually indicates a GPU driver or hardware issue. Try updating your graphics drivers.", err_str, __FILE__, __LINE__); \
255
+
/* Handle device lost gracefully instead of fatal error */ \
256
+
vk.device_lost=qtrue; \
257
+
ri.Printf(PRINT_ERROR, "Vulkan: Device lost (%s) at %s:%d - GPU driver issue. Rendering may be disabled.\n", err_str, __FILE__, __LINE__); \
258
+
ri.Printf(PRINT_ERROR, "Vulkan: Try restarting the application or updating GPU drivers.\n"); \
0 commit comments