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/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 d67b347ff..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,20 +288,23 @@ 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, queued := true) -> bool { if result == .SUCCESS {return true} - if vk_lost(d, result, what) {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. +// 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) -> 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 { + // 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} @@ -499,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 667ee20b0..a7444a7e5 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) - created := vk_check(d, d.dvk.CreateComputePipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name) - vk_pipeline_cache_close(d, key, cache, feedback, created) + started := time.tick_now() + 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, 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) - created := vk_check(d, d.dvk.CreateGraphicsPipelines(d.handle, cache, 1, &info, nil, &p.handle), desc.name) - vk_pipeline_cache_close(d, key, cache, feedback, created) + started := time.tick_now() + 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, 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)