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/3] 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 103a9f11cdf678b6f6f3b4bcb003a1a291112b37 Mon Sep 17 00:00:00 2001 From: 5hif7y <44300833+5hif7y@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:00:08 -0300 Subject: [PATCH 2/3] Weigh the pipeline store's saves by the time measured around creation The time a pipeline added came from VkPipelineCreationFeedback.duration, which is 0 on a driver that does not set VALID: such a run wrote the store only at device_destroy, and a killed editor lost all it compiled. The CPU now measures the creation call, on every driver. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/mirai-rendering/references/rhi.md | 4 ++-- rhi/vulkan_resources.odin | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.agents/skills/mirai-rendering/references/rhi.md b/.agents/skills/mirai-rendering/references/rhi.md index 44c7c56ae..f19380d5e 100644 --- a/.agents/skills/mirai-rendering/references/rhi.md +++ b/.agents/skills/mirai-rendering/references/rhi.md @@ -267,8 +267,8 @@ For a renderer that generates frames (`rhi/present.odin`): dictionary of megabytes). - The file belongs to one device, driver and cache UUID, and is read whole or not at all: another device, another version or a file that does not read back exactly is ignored and replaced. -- It is rewritten in one rename once what the driver took to compile the pipelines added since the - last write (`VkPipelineCreationFeedback`) passes `PIPELINE_STORE_SAVE_SHARE` times what that +- It is rewritten in one rename once the time the pipelines added since the last write took to + create (measured around `vkCreate*Pipelines`) passes `PIPELINE_STORE_SAVE_SHARE` times what that write took, from the thread that compiled, and when the device is destroyed: a run that crashes, is killed or loses its device loses little compiling, and cheap pipelines do not rewrite the file. A write holds the diff --git a/rhi/vulkan_resources.odin b/rhi/vulkan_resources.odin index eebcf4094..d02e383ea 100644 --- a/rhi/vulkan_resources.odin +++ b/rhi/vulkan_resources.odin @@ -619,9 +619,11 @@ vk_pipeline_cache_open :: proc(d: ^Device, key: u64) -> (cache: vk.PipelineCache } // Keeps what the driver compiled into cache under key, unless the pipeline came -// from the blob kept for it, and destroys cache. +// from the blob kept for it, and destroys cache. took: how long the creation +// call ran, which the store weighs against its last save; the CPU measures it, +// since a driver may leave VkPipelineCreationFeedback without VALID. @(private) -vk_pipeline_cache_close :: proc(d: ^Device, key: u64, cache: vk.PipelineCache, feedback: vk.PipelineCreationFeedback, created: bool) { +vk_pipeline_cache_close :: proc(d: ^Device, key: u64, cache: vk.PipelineCache, feedback: vk.PipelineCreationFeedback, created: bool, took: time.Duration) { if cache == 0 {return} defer d.dvk.DestroyPipelineCache(d.handle, cache, nil) if !created || feedback.flags >= {.VALID, .APPLICATION_PIPELINE_CACHE_HIT} {return} @@ -632,7 +634,6 @@ vk_pipeline_cache_close :: proc(d: ^Device, key: u64, cache: vk.PipelineCache, f if d.dvk.GetPipelineCacheData(d.handle, cache, &size, raw_data(data)) != .SUCCESS || size == 0 {delete(data, d.allocator); return} defer delete(data, d.allocator) sync.lock(&d.pipelines_kept.lock) - took := time.Duration(feedback.duration) if .VALID in feedback.flags else 0 due := pipeline_store_put(&d.pipelines_kept, key, data[:size], took) sync.unlock(&d.pipelines_kept.lock) if due {pipeline_store_save(&d.pipelines_kept, string(d.store_path[:d.store_path_len]))} @@ -681,8 +682,9 @@ pipeline_create_compute :: proc(d: ^Device, desc: Compute_Pipeline_Desc) -> Pipe } key := pipeline_key_compute(desc) cache := vk_pipeline_cache_open(d, key) + started := time.tick_now() 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) + vk_pipeline_cache_close(d, key, cache, feedback, created, time.tick_since(started)) if !created {vk_release_pipeline(d, &p); return 0} vk_set_name(d, .PIPELINE, u64(p.handle), desc.name) return vk_pipeline_add(d, &p) @@ -783,8 +785,9 @@ pipeline_create_graphics :: proc(d: ^Device, desc: Graphics_Pipeline_Desc) -> Pi } key := pipeline_key_graphics(desc) cache := vk_pipeline_cache_open(d, key) + started := time.tick_now() 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) + vk_pipeline_cache_close(d, key, cache, feedback, created, time.tick_since(started)) if !created {vk_release_pipeline(d, &p); return 0} vk_set_name(d, .PIPELINE, u64(p.handle), desc.name) return vk_pipeline_add(d, &p) From a7f852d5137d490613ba02c866a11c5388ccec6a Mon Sep 17 00:00:00 2001 From: tomaszbk-pc Date: Sun, 15 Nov 2026 21:49:54 -0300 Subject: [PATCH 3/3] 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)