ludic/runtime/native/vk.ludic
2026-09-30 17:18:48 +03:00

58 lines
4.5 KiB
Text

# ============================================================================
# vk.ludic — Vk.*: Vulkan for Ludic.
#
# Every command of Vulkan 1.0-1.4 and of the extensions the render3d Vulkan renderer
# is built around is bound in vk_api.ludic (generated by `ludic-dev vkgen` from the
# Vulkan registry), with every constant and every struct's size and field offsets.
# Vk.<snake_name>(...) calls one: Vk.create_instance(info, null, out). Structs are
# plain memory filled by field name:
# let ci = bytes(VkInstanceCreateInfo_sizeof)
# Vk.zero(ci, VkInstanceCreateInfo_sizeof)
# Vk.put_i32(ci, VkInstanceCreateInfo_sType, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO)
#
# Numbers: a C float is float bits in an int; uint64_t, VkDeviceSize and
# non-dispatchable handles are `long`. A negative long has to come from a `long`
# variable - an int literal passed straight to a long parameter is zero-extended.
#
# The loader is opened at run time by Vk.open() (vk_win.ll / vk_mac.ll), never
# linked: 0 means this machine has no Vulkan, and the program carries on without it.
# ============================================================================
import "vk_api.ludic"
# Streamline (NVIDIA DLSS, Ray Reconstruction, Frame Generation, Reflex), Windows only: Vk.sl_prefer(1)
# before Vk.open() loads sl.interposer.dll as the Vulkan loader when it is beside the program, and
# Vk.sl_active() says whether it was. Each Vk.sl_* is the sl* export of the same name and returns
# its sl::Result (0 is eOk); -1 means there is no Streamline (macOS, or the DLL missing). The
# structs are plain memory, laid out as the SDK headers (include/sl_*.h, SDK 2.14.1) declare them.
# Once a frame: on macOS drains what MoltenVK and the layer autoreleased during the last one (a
# program pumping its own events has no other pool); nothing elsewhere.
extern function vk_frame_pool() = "lvk_frame_pool"
extern function vk_sl_prefer(on: int) = "lvk_sl_prefer"
extern function vk_sl_active() -> int = "lvk_sl_active"
extern function vk_sl_init(pref: pointer, sdk_version: long) -> int = "lsl_slInit"
extern function vk_sl_shutdown() -> int = "lsl_slShutdown"
extern function vk_sl_is_feature_supported(feature: int, adapter_info: pointer) -> int = "lsl_slIsFeatureSupported"
extern function vk_sl_is_feature_loaded(feature: int, loaded: pointer) -> int = "lsl_slIsFeatureLoaded"
extern function vk_sl_get_feature_requirements(feature: int, requirements: pointer) -> int = "lsl_slGetFeatureRequirements"
extern function vk_sl_get_feature_function(feature: int, name: pointer, function_out: pointer) -> int = "lsl_slGetFeatureFunction"
extern function vk_sl_get_new_frame_token(token_out: pointer, frame_index: pointer) -> int = "lsl_slGetNewFrameToken"
extern function vk_sl_set_tag_for_frame(frame: pointer, viewport: pointer, tags: pointer, num_tags: int, cmd_buffer: pointer) -> int = "lsl_slSetTagForFrame"
extern function vk_sl_set_constants(constants: pointer, frame: pointer, viewport: pointer) -> int = "lsl_slSetConstants"
extern function vk_sl_evaluate_feature(feature: int, frame: pointer, inputs: pointer, num_inputs: int, cmd_buffer: pointer) -> int = "lsl_slEvaluateFeature"
extern function vk_sl_free_resources(feature: int, viewport: pointer) -> int = "lsl_slFreeResources"
# a feature function obtained with Vk.sl_get_feature_function, called with its arguments
extern function vk_sl_call_p(fn: pointer, a: pointer) -> int = "lsl_call_p"
extern function vk_sl_call_pp(fn: pointer, a: pointer, b: pointer) -> int = "lsl_call_pp"
extern function vk_sl_call_ppp(fn: pointer, a: pointer, b: pointer, c: pointer) -> int = "lsl_call_ppp"
extern function vk_sl_call_ip(fn: pointer, a: int, b: pointer) -> int = "lsl_call_ip"
# a command-buffer command with three counts through a pointer (vkCmdDrawMeshTasksEXT, which the
# Streamline interposer does not export; looked up with vkGetDeviceProcAddr)
extern function vk_sl_call_piii(fn: pointer, a: pointer, b: int, c: int, d: int) = "lsl_call_piii"
# acceleration-structure commands through a pointer from vkGetDeviceProcAddr (the interposer exports none)
extern function vk_sl_call_pppp(fn: pointer, a: pointer, b: pointer, c: pointer, d: pointer) -> int = "lsl_call_pppp"
extern function vk_sl_call_plp(fn: pointer, a: pointer, b: long, c: pointer) = "lsl_call_plp"
extern function vk_sl_call_pippp(fn: pointer, a: pointer, b: int, c: pointer, d: pointer, e: pointer) = "lsl_call_pippp"
extern function vk_sl_call_pipp(fn: pointer, a: pointer, b: int, c: pointer, d: pointer) = "lsl_call_pipp"
extern function vk_sl_call_pp_l(fn: pointer, a: pointer, b: pointer) -> long = "lsl_call_pp_l"