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

Phase 1 — end-to-end shader synthesis driver.

Render template → write GLSL to disk → compile to SPIR-V via
`glslangValidator` → cache by content hash → return SPV path
ready for `Nx.Vulkan.Native.leapfrog_chain_synth/6`.

## Cache layout

    ~/.exmc/gpu_node/spv/{spec_hash}.spv

where `spec_hash = :crypto.hash(:sha256, glsl_source) |> Base.encode16(case: :lower)`.

Re-synthesizing the same spec is a hash-match → instant cache hit
(no disk write, no glslangValidator call).

## Usage

    iex> spec = Nx.Vulkan.ChainShaderSpecs.beta()
    iex> {:ok, spv_path} = Nx.Vulkan.Synthesis.compile(spec)
    iex> push = Nx.Vulkan.ChainShaderSpecs.beta_push(1, 32, 0.05, 2.0, 5.0)
    iex> Nx.Vulkan.Native.leapfrog_chain_synth(q_ref, p_ref, inv_mass_ref,
    ...>                                       push, 32, spv_path)
    {:ok, {q_chain, p_chain, grad_chain, logp_chain}}

# `clear_cache`

Clear the SPV cache directory. Useful for tests.

# `compile`

Compile a `%FamilySpec{}` to SPIR-V on disk.

Returns `{:ok, spv_path}` on success or `{:error, reason}` on
`glslangValidator` failure.

# `compile_with_source`

Render + compile + return both spv_path AND the rendered GLSL source.
Useful for debugging — when something goes wrong post-compile (e.g. a
GPU dispatch failure), you have the source string at hand.

---

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