Module Sarek_vulkan.Vulkan_api_memory

module Device = Vulkan_api_device
type 'a buffer = {
  1. buffer : Vulkan_types.vk_buffer;
  2. memory : Vulkan_types.vk_device_memory;
  3. size : int;
  4. elem_size : int;
  5. device : Device.t;
  6. mutable mapped_ptr : unit Ctypes.ptr option;
  7. mapped_cached : bool;
    (*

    The mapping is of HOST_CACHED memory, so the host can read it at memory speed. A mapping of device memory behind the PCIe BAR is write-combined and uncached: writes are fast, reads run at a few tens of MB/s.

    *)
}
val live_allocations : int Stdlib.Atomic.t
val inject_alloc_failure : int Stdlib.ref
val force_unmapped : bool Stdlib.Atomic.t

Test hook: while true, alloc places buffers in DEVICE_LOCAL memory that is never host-mapped, even where HOST_VISIBLE device memory exists, so the staged and imported copy paths of Vulkan_api_transfer can be exercised on a machine whose VRAM is host-visible. Production code never sets it.

val find_memory_type : Device.t -> int -> int -> int option

Find suitable memory type

val find_memory_type_excluding : Device.t -> int -> required:int -> excluded:int -> int option

Like find_memory_type, for a type that also has none of the excluded flags.

val memory_type_is_cached : Device.t -> int -> bool

Whether memory type index is HOST_CACHED.

val vk_whole_size : Unsigned.UInt64.t
val create_transient_pool : Device.t -> Vulkan_types.vk_command_pool

A command pool private to one call: vkCmdXxx, vkBeginCommandBuffer and allocation need external synchronisation of their pool, and these copies run on whichever domain the caller is, so sharing device.command_pool would need a lock held across the recording. A transient pool per call needs none and adds no lock to the order batch_lock -> queue_lock.

val allocate_copy_command_buffer : Device.t -> Vulkan_types.vk_command_pool -> Vulkan_types.vk_command_buffer Ctypes.structure Ctypes_static.ptr Ctypes.ptr
val begin_one_time : Vulkan_types.vk_command_buffer Ctypes.structure Ctypes_static.ptr -> unit
val submit_and_wait : Device.t -> Vulkan_types.vk_command_buffer Ctypes.structure Ctypes_static.ptr Ctypes_static.ptr -> unit
val run_single_time_command : Device.t -> (Vulkan_types.vk_command_buffer Ctypes.structure Ctypes_static.ptr -> unit) -> unit

Record record_fn into a one-time command buffer, submit it and wait.

val staging_buffers_created : int Stdlib.Atomic.t

Test instrumentation, not an API: staging buffers created since the library was loaded. Lets a test assert that a copy took the staging-free path.

val create_staging_buffer : ?cached:bool -> Device.t -> int -> int -> Vulkan_types.vk_buffer * Unsigned.UInt64.t * unit Ctypes_static.ptr

A mapped HOST_VISIBLE | HOST_COHERENT buffer of size bytes. With ~cached:true the memory is HOST_CACHED when the device has such a type (the host reads it at memory speed; uncached staging memory reads at ~0.25 GB/s), otherwise the plain type.

val alloc_once : Device.t -> int -> ('a, 'b) Stdlib.Bigarray.kind -> 'c buffer
val alloc_custom_once : Device.t -> size:int -> elem_size:int -> 'a buffer
val release_now : 'a buffer -> unit

Destroy buf's Vulkan objects. Only when no launch can use the buffer.

val alloc : Sarek_vulkan.Vulkan_api_release.Device.t -> int -> ('a, 'b) Stdlib.Bigarray.kind -> 'c buffer
val alloc_custom : Sarek_vulkan.Vulkan_api_release.Device.t -> size:int -> elem_size:int -> 'a buffer
val free : 'a buffer -> unit

Queue the release of buf; see Vulkan_api_release. Safe from a GC finaliser.

val device_ptr : 'a -> nativeint

Vulkan doesn't expose device pointers like CUDA. Return 0 as placeholder. Binding uses the buffer handle directly via set_arg_buffer.

val is_zero_copy : 'a -> bool

Vulkan always uses explicit transfers (vkMapMemory/memcpy), never zero-copy

val host_to_device : src:('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> dst:'c buffer -> unit
val device_to_host : src:'a buffer -> dst:('b, 'c, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> unit
val host_ptr_to_device : src_ptr:unit Ctypes_static.ptr -> byte_size:int -> dst:'a buffer -> unit
val device_to_host_ptr : src:'a buffer -> dst_ptr:unit Ctypes_static.ptr -> byte_size:int -> unit
val device_to_device : src:'a -> dst:'b -> 'c
val memset : 'a -> 'b -> 'c