@@ -947,23 +947,17 @@ void end_command_buffer(VkCommandBuffer command_buffer, const char *location)
947947 ri .Printf (PRINT_ERROR , "Vulkan: This may cause rendering artifacts or instability\n" );
948948 ri .Printf (PRINT_ERROR , "Vulkan: Rendering disabled. Try restarting the application or updating GPU drivers.\n" );
949949 ri .Printf (PRINT_ERROR , "Vulkan: Video playback may not work until device is recovered.\n" );
950- // Skip wait if device is lost - it will fail anyway
951950 return ;
952951 } else {
953952 // For other errors, use the standard error handling
954953 VK_CHECK (submit_result );
955954 }
956955 }
957956
958- // Only wait if device is not lost
959- if (!vk .device_lost ) {
960- vk_queue_wait_idle ();
961- }
962-
963- // Only free command buffers if device is not lost
964- if (!vk .device_lost && vk .device != VK_NULL_HANDLE ) {
965- qvkFreeCommandBuffers ( vk .device , vk .command_pool , 1 , & command_buffer );
966- }
957+ // Don't wait for queue idle after every command submission - this is unnecessary and can discover device loss prematurely.
958+ // Use fences/semaphores for synchronization instead. Queue waits should only be used when
959+ // actually necessary (resource cleanup, reading back results, etc.)
960+ // The command buffer will be freed when it's actually finished, not immediately.
967961}
968962
969963VkInstance VK_GetInstanceHandle ( void )
@@ -10062,14 +10056,42 @@ void vk_queue_wait_idle( void ) {
1006210056 return ;
1006310057 }
1006410058
10059+ // Check if we've detected problematic shaders during initialization
10060+ // If so, use a more cautious approach - the device might be in an unstable state
10061+ #ifdef USE_VULKAN
10062+ #include "vk_shader_validation.h"
10063+ extern int vk_get_problematic_shader_count (void );
10064+ static qboolean initialization_phase = qtrue ; // Track if we're still in initialization
10065+ if (initialization_phase && vk_get_problematic_shader_count () > 0 ) {
10066+ // During initialization with problematic shaders detected, skip wait to avoid discovering device loss
10067+ // The problematic shader may have already submitted a command that causes device loss
10068+ // We'll discover the loss later during normal operations if it persists
10069+ ri .Printf (PRINT_DEVELOPER , "Vulkan: Skipping queue wait during initialization - problematic shaders detected\n" );
10070+ // Mark initialization as complete after a few frames
10071+ static int frame_count = 0 ;
10072+ if (++ frame_count > 10 ) {
10073+ initialization_phase = qfalse ;
10074+ }
10075+ return ;
10076+ }
10077+ initialization_phase = qfalse ; // Mark initialization as complete
10078+ #endif
10079+
10080+ // Check device status before waiting - use GetDeviceQueue2 or similar to verify device is still valid
10081+ // If device was lost, QueueWaitIdle will return VK_ERROR_DEVICE_LOST immediately
10082+ // We can't prevent this, but we can handle it gracefully
1006510083 VkResult result = qvkQueueWaitIdle ( vk .queue );
1006610084 if (result != VK_SUCCESS ) {
1006710085 if (result == VK_ERROR_DEVICE_LOST ) {
10068- vk .device_lost = qtrue ; // Mark device as lost
10069- vk_reset_memory_tracking_on_device_lost (); // Reset memory tracking so recovery knows memory is available
10070- ri .Printf (PRINT_ERROR , "Vulkan: Device lost during queue wait - GPU driver issue\n" );
10071- ri .Printf (PRINT_ERROR , "Vulkan: This may cause rendering artifacts or instability\n" );
10072- ri .Printf (PRINT_WARNING , "Vulkan: Recovery will be attempted automatically\n" );
10086+ // Device was already lost (from a previous command) - we're just discovering it now
10087+ // Don't treat this as a new error, just mark it and continue
10088+ if (!vk .device_lost ) {
10089+ vk .device_lost = qtrue ; // Mark device as lost
10090+ vk_reset_memory_tracking_on_device_lost (); // Reset memory tracking so recovery knows memory is available
10091+ ri .Printf (PRINT_WARNING , "Vulkan: Device lost detected during queue wait (from previous command)\n" );
10092+ ri .Printf (PRINT_WARNING , "Vulkan: This was likely caused by a problematic shader or command\n" );
10093+ ri .Printf (PRINT_WARNING , "Vulkan: Recovery will be attempted automatically\n" );
10094+ }
1007310095 // Don't terminate the engine for device lost - allow initialization to continue
1007410096 return ;
1007510097 } else {
@@ -10079,12 +10101,6 @@ void vk_queue_wait_idle( void ) {
1007910101 }
1008010102}
1008110103
10082- /*
10083- =============================================================================
10084- Vulkan 1.4 Maintenance5 Features
10085- =============================================================================
10086- */
10087-
1008810104// Get buffer device address (VK_KHR_maintenance5 / Vulkan 1.4 core)
1008910105VkDeviceAddress vk_get_buffer_device_address (VkBuffer buffer ) {
1009010106 if (!vk_advanced .maintenance5 || !qvkGetBufferDeviceAddress ) {
0 commit comments