Module Sarek_vulkan.Vulkan_api_base

val memcpy : unit Ctypes_static.ptr -> unit Ctypes_static.ptr -> Unsigned.size_t -> unit Ctypes_static.ptr

memcpy from libc for memory transfers

val u32 : int -> Unsigned.UInt32.t

Helper to convert OCaml int to Unsigned.UInt32.t

Exceptions

exception Vk_result_error of Vulkan_types.vk_result * string

Deprecated: no longer raised. check below now raises the canonical Vulkan_error.Vulkan_error (a Backend_error alias) via the shared Sarek_backend_error.Backend_error.Make.check funnel. Kept only so out-of-tree code matching on Vulkan_api_base.Vk_result_error (code, ctx) (or the re-exported Vulkan_api.Vk_result_error) still compiles (this library is opam-published).

  • deprecated no longer raised; Vulkan_api_base.check now raises Vulkan_error.Vulkan_error (Backend_error) - catch that instead
val check : string -> Vulkan_types.vk_result -> unit

Check Vulkan result and raise a canonical Backend_error on failure.

Fences

val fence_warn_interval_ns : int64

Interval between warnings while a fence wait goes on, in nanoseconds.

val fence_wait_bound_parsed : (int64 option, string) Stdlib.result

Optional bound on a fence wait, from SPOC_VULKAN_FENCE_TIMEOUT_S (seconds, positive), read once when the library is loaded. Unset means unbounded: a wait on submitted work ends only when the work completes or the device reports an error, because a caller that gave up early could free memory the GPU still uses. The bound exists for tests that use it as a hang detector. A malformed value is kept as Error and refused by check_fence_wait_bound, called when a device is created, so it never surfaces after a submission.

val check_fence_wait_bound : unit -> unit
val inject_wait_failure : Vulkan_types.vk_result option Stdlib.ref

Test hook: while Some r, every fence wait fails with r before waiting (the caller should have made the queue idle first and clears the hook).

val fence_wait_count : int Stdlib.Atomic.t

Test instrumentation, not an API: number of vkWaitForFences sequences started and of fence-carrying vkQueueSubmits that succeeded, since the library was loaded. Instrumentation for tests that assert how many host waits a run of launches costs.

val submission_count : int Stdlib.Atomic.t
val wait_fence : string -> Vulkan_types.vk_device Ctypes.structure Ctypes_static.ptr -> Vulkan_types.vk_fence -> unit

Wait for fence on device until it is signalled. Logs a warning naming ctx every fence_warn_interval_ns. Raises the canonical error of check on a device error, and Synchronization_failed only when fence_wait_bound_parsed sets a bound and it is reached.

val inject_status_failure : Vulkan_types.vk_result option Stdlib.ref

Test hook: while Some r, every fence status query returns r.

val fence_signalled : string -> Vulkan_types.vk_device Ctypes.structure Ctypes_static.ptr -> Vulkan_types.vk_fence -> bool

Whether fence has signalled, without blocking. Raises the canonical error of check on a device error.

val reset_fence : string -> Vulkan_types.vk_device Ctypes.structure Ctypes_static.ptr -> Vulkan_types.vk_fence -> unit

Reset fence on device. The fence must not be pending in a queue.

type tracked_fence = {
  1. handle : Vulkan_types.vk_fence;
  2. mutable pending : bool;
}

A fence with its submission state. Invariant: pending = true implies the fence was handed to a successful vkQueueSubmit and has not been waited for since. Waits happen only when pending is set, so a fence that was never submitted (or whose submission failed) is never waited on.

val create_tracked_fence : Vulkan_types.vk_device Ctypes.structure Ctypes_static.ptr -> tracked_fence
val await_fence : string -> Vulkan_types.vk_device Ctypes.structure Ctypes_static.ptr -> tracked_fence -> unit

Wait for fence if it is pending, then mark it not pending.

val submit_with_fence : string -> Vulkan_types.vk_device Ctypes.structure Ctypes_static.ptr -> tracked_fence -> (Vulkan_types.vk_fence -> Vulkan_types.vk_result) -> unit

Reset fence and pass it to submit; mark it pending only when submit returns VK_SUCCESS. The fence must not be pending.

val destroy_tracked_fence : string -> Vulkan_types.vk_device Ctypes.structure Ctypes_static.ptr -> tracked_fence -> unit

Wait out a pending submission, then destroy fence (VUID-vkDestroyFence-fence-01120).

SPIR-V Compilation

val needs_vulkan_1_1 : string -> bool

A shader that uses subgroup operations (GL_KHR_shader_subgroup_*, emitted by the warp shuffles) needs SPIR-V 1.3, i.e. the Vulkan 1.1 target environment. It is requested for those shaders ONLY: Vulkan 1.1 changes the storage class of buffer blocks, which the note below keeps away from every other shader. The device side is already at 1.2 (Vulkan_api_device).

val compile_glsl_to_spirv_cli : entry_point:string -> string -> string

Compile GLSL to SPIR-V using glslangValidator. Requires glslangValidator in PATH.

val compile_glsl_to_spirv : entry_point:string -> string -> string

Compile GLSL to SPIR-V using Shaderc if available, otherwise fallback to CLI

val glslang_available : unit -> bool

Check if glslangValidator is available