From c14ea8d779d13a1b198a6fe2e0328a78496f09af Mon Sep 17 00:00:00 2001 From: 5hif7y <44300833+5hif7y@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:56:48 -0300 Subject: [PATCH 1/2] Ask the driver for a fault only after a loss the validation layer records When pipeline creation returns VK_ERROR_DEVICE_LOST, the validation layer has not marked the device lost and reports vkGetDeviceFaultInfoEXT as a validation error. Pipeline creation now marks the loss without asking for its description. Co-Authored-By: Claude Opus 5.5 --- rhi/vulkan_device.odin | 12 +++++++----- rhi/vulkan_resources.odin | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/rhi/vulkan_device.odin b/rhi/vulkan_device.odin index d67b347ff..6a480fb53 100644 --- a/rhi/vulkan_device.odin +++ b/rhi/vulkan_device.odin @@ -287,20 +287,22 @@ set_error :: proc(d: ^Device, format: string, args: ..any) { } @(private) -vk_check :: proc(d: ^Device, result: vk.Result, what: string) -> bool { +vk_check :: proc(d: ^Device, result: vk.Result, what: string, described := true) -> bool { if result == .SUCCESS {return true} - if vk_lost(d, result, what) {return false} + if vk_lost(d, result, what, described) {return false} set_error(d, "%s failed: %v", what, result) return false } // Whether a result reports the device lost, which marks it with what the -// driver says of the fault; other results are the caller's. +// driver says of the fault; other results are the caller's. described false: +// a loss the validation layer does not record (pipeline creation), for which +// it refuses vkGetDeviceFaultInfoEXT as asked of a device that is not lost. @(private) -vk_lost :: proc(d: ^Device, result: vk.Result, what: string) -> bool { +vk_lost :: proc(d: ^Device, result: vk.Result, what: string, described := true) -> bool { if result != .ERROR_DEVICE_LOST {return false} description: string - if d.fault_info && !d.lose_provoked { + if d.fault_info && !d.lose_provoked && described { // No arrays asked for: the description alone, with INCOMPLETE. counts := vk.DeviceFaultCountsEXT{sType = .DEVICE_FAULT_COUNTS_EXT} info := vk.DeviceFaultInfoEXT{sType = .DEVICE_FAULT_INFO_EXT} diff --git a/rhi/vulkan_resources.odin b/rhi/vulkan_resources.odin index 667ee20b0..eebcf4094 100644 --- a/rhi/vulkan_resources.odin +++ b/rhi/vulkan_resources.odin @@ -681,7 +681,7 @@ pipeline_create_compute :: proc(d: ^Device, desc: Compute_Pipeline_Desc) -> Pipe } key := pipeline_key_compute(desc) cache := vk_pipeline_cache_open(d, key) - created := vk_check(d, d.dvk.CreateComputePipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name) + created := vk_check(d, d.dvk.CreateComputePipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name, described = false) vk_pipeline_cache_close(d, key, cache, feedback, created) if !created {vk_release_pipeline(d, &p); return 0} vk_set_name(d, .PIPELINE, u64(p.handle), desc.name) @@ -783,7 +783,7 @@ pipeline_create_graphics :: proc(d: ^Device, desc: Graphics_Pipeline_Desc) -> Pi } key := pipeline_key_graphics(desc) cache := vk_pipeline_cache_open(d, key) - created := vk_check(d, d.dvk.CreateGraphicsPipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name) + created := vk_check(d, d.dvk.CreateGraphicsPipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name, described = false) vk_pipeline_cache_close(d, key, cache, feedback, created) if !created {vk_release_pipeline(d, &p); return 0} vk_set_name(d, .PIPELINE, u64(p.handle), desc.name) From a7f852d5137d490613ba02c866a11c5388ccec6a Mon Sep 17 00:00:00 2001 From: tomaszbk-pc Date: Sun, 15 Nov 2026 21:49:54 -0300 Subject: [PATCH 2/2] Skip the fault query of a pipeline-creation loss only under the validation layer The query is valid after any VK_ERROR_DEVICE_LOST; only the validation layer flags it when no submission or wait reported the loss. Without the layer the driver's description of such a loss is kept. The workaround is listed under Drivers in the dependency workarounds. Co-Authored-By: Claude Opus 5.5 --- docs/ODIN_WORKAROUNDS.md | 1 + rhi/vulkan_device.odin | 17 ++++++++++------- rhi/vulkan_resources.odin | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/ODIN_WORKAROUNDS.md b/docs/ODIN_WORKAROUNDS.md index 041604f6e..5aec52d93 100644 --- a/docs/ODIN_WORKAROUNDS.md +++ b/docs/ODIN_WORKAROUNDS.md @@ -44,3 +44,4 @@ Defects of GPU drivers that the GPU tests reach. | Marker in code | Upstream | Remove when | | --- | --- | --- | | `keep_one` (`rhi/shared_device/shared_device.odin`): the GPU tests of a process keep one device alive from the first `hold` to the end; the NVIDIA Windows driver 616.92 (`nvoglv64.dll`) frees the context of the worker threads of the last device of a process while they still run, and one of them then calls through freed memory (0xC0000005) | none | without `keep_one`, `mirai test rhi/tests rhi_devices_are_created_and_destroyed_in_turn_and_on_several_threads` passes 20 runs in a row under `MIRAI_VALIDATION=1` on that driver's successor | +| `fault_query_unqueued` (`rhi/vulkan_device.odin`): with the validation layer on, `vk_lost` asks no fault description of a loss that pipeline creation reported; the layer counts a device as lost only once a submission or a wait reported it, and flags `vkGetDeviceFaultInfoEXT` after any other `VK_ERROR_DEVICE_LOST` (VUID-vkGetDeviceFaultInfoEXT-device-07336) | none | the layer takes a loss from any call: `vk_lost` asks on every loss, and a run under validation that loses the device in `vkCreateComputePipelines` has no validation message | diff --git a/rhi/vulkan_device.odin b/rhi/vulkan_device.odin index 6a480fb53..428fe5f66 100644 --- a/rhi/vulkan_device.odin +++ b/rhi/vulkan_device.odin @@ -267,6 +267,7 @@ Device :: struct { failure_text: string, failure_buffer: [FAILURE_TEXT_BYTES]u8, fault_info: bool, // VK_EXT_device_fault: the driver describes a loss + validation_layer: bool, // VK_LAYER_KHRONOS_validation is enabled memory_budget: bool, // VK_EXT_memory_budget: the driver says what memory the process holds and may hold waited_out: bool, // a wait passed GPU_WAIT_LIMIT_NS: the GPU may still run that work lose_asked: bool, // device_lose @@ -287,22 +288,23 @@ set_error :: proc(d: ^Device, format: string, args: ..any) { } @(private) -vk_check :: proc(d: ^Device, result: vk.Result, what: string, described := true) -> bool { +vk_check :: proc(d: ^Device, result: vk.Result, what: string, queued := true) -> bool { if result == .SUCCESS {return true} - if vk_lost(d, result, what, described) {return false} + if vk_lost(d, result, what, queued) {return false} set_error(d, "%s failed: %v", what, result) return false } // Whether a result reports the device lost, which marks it with what the -// driver says of the fault; other results are the caller's. described false: -// a loss the validation layer does not record (pipeline creation), for which -// it refuses vkGetDeviceFaultInfoEXT as asked of a device that is not lost. +// driver says of the fault; other results are the caller's. queued false: a +// call other than a submission or a wait reported it (pipeline creation). @(private) -vk_lost :: proc(d: ^Device, result: vk.Result, what: string, described := true) -> bool { +vk_lost :: proc(d: ^Device, result: vk.Result, what: string, queued := true) -> bool { if result != .ERROR_DEVICE_LOST {return false} description: string - if d.fault_info && !d.lose_provoked && described { + // fault_query_unqueued: the validation layer takes a loss only from a submission or a wait, + // and reports vkGetDeviceFaultInfoEXT after any other as made on a device that is not lost. + if d.fault_info && !d.lose_provoked && (queued || !d.validation_layer) { // No arrays asked for: the description alone, with INCOMPLETE. counts := vk.DeviceFaultCountsEXT{sType = .DEVICE_FAULT_COUNTS_EXT} info := vk.DeviceFaultInfoEXT{sType = .DEVICE_FAULT_INFO_EXT} @@ -501,6 +503,7 @@ vk_create_instance_and_device :: proc(d: ^Device, desc: Device_Desc) -> bool { if d.debug_utils {append(&extensions, "VK_EXT_debug_utils")} enabled_layers := make([dynamic]cstring, 0, 2, context.temp_allocator) if validation {append(&enabled_layers, "VK_LAYER_KHRONOS_validation")} + d.validation_layer = validation app := vk.ApplicationInfo{ sType = .APPLICATION_INFO, diff --git a/rhi/vulkan_resources.odin b/rhi/vulkan_resources.odin index eebcf4094..60b216952 100644 --- a/rhi/vulkan_resources.odin +++ b/rhi/vulkan_resources.odin @@ -681,7 +681,7 @@ pipeline_create_compute :: proc(d: ^Device, desc: Compute_Pipeline_Desc) -> Pipe } key := pipeline_key_compute(desc) cache := vk_pipeline_cache_open(d, key) - created := vk_check(d, d.dvk.CreateComputePipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name, described = false) + created := vk_check(d, d.dvk.CreateComputePipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name, queued = false) vk_pipeline_cache_close(d, key, cache, feedback, created) if !created {vk_release_pipeline(d, &p); return 0} vk_set_name(d, .PIPELINE, u64(p.handle), desc.name) @@ -783,7 +783,7 @@ pipeline_create_graphics :: proc(d: ^Device, desc: Graphics_Pipeline_Desc) -> Pi } key := pipeline_key_graphics(desc) cache := vk_pipeline_cache_open(d, key) - created := vk_check(d, d.dvk.CreateGraphicsPipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name, described = false) + created := vk_check(d, d.dvk.CreateGraphicsPipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name, queued = false) vk_pipeline_cache_close(d, key, cache, feedback, created) if !created {vk_release_pipeline(d, &p); return 0} vk_set_name(d, .PIPELINE, u64(p.handle), desc.name)