# `Nx.Vulkan.PipelineCache`
[🔗](https://github.com/borodark/nx_vulkan/blob/main/lib/nx_vulkan/pipeline_cache.ex#L1)

Phase 2 W5 — disk persistence for spirit's `VkPipelineCache`.

The vkPipelineCache holds compiled SPIR-V → device ISA. Without
persistence, every BEAM restart pays the full backend-compile cost
on first dispatch (~30-200 ms per shader on NVIDIA Linux). With
persistence, the second-and-later restarts of a process that has
the cache file get cache hits — `vkCreateComputePipelines` skips
the compile entirely.

## File layout

    ~/.exmc/gpu_node/pipeline_cache/{device_uuid_hex}.bin

The `device_uuid_hex` is the lowercased hex of `VkPhysicalDevice
pipelineCacheUUID` (16 bytes → 32 hex chars). Different GPUs and
different drivers produce different UUIDs, so the file is
inherently device-specific. The driver itself silently rejects
blobs whose embedded header doesn't match the running device, so
even if the wrong file lands in the directory it just produces
a fresh empty cache (with a stderr warning).

## Usage

    # At application start, before any pipelines are built:
    Nx.Vulkan.PipelineCache.load()

    # At application shutdown, or periodically:
    Nx.Vulkan.PipelineCache.persist()

# `clear`

Convenience for benchmarks / tests — clear the cache directory.

# `default_path`

Path the cache file would land at for the current device.

# `device_uuid_hex`

Lowercased hex of the device's 16-byte pipelineCacheUUID.

# `load`

Load the disk cache (if present) into spirit's pipeline cache.
Returns `:ok` on success, including the "no file yet" case.

# `persist`

Persist spirit's current pipeline cache to disk via atomic
write-temp-rename. Returns `:ok`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
