tycho_metal

    Pure-MoonBit Apple Metal bindings (zero Objective-C compiler flags, runtime-loaded Metal.framework / QuartzCore / Foundation)

    metal
    macos
    ios
    graphics
    gpu
    tycho
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    16 minutes ago
    Downloads
    3

    No dependencies

    #laplaceliu/tycho_metal

    L0 native Apple Metal bindings for Tycho (macOS & iOS).

    Uses pure C99 dlopen + libobjc.A.dylib (objc_msgSend) against Metal.framework, QuartzCore.framework, and Foundation.framework so that every native target (macOS, Linux, Windows) compiles cleanly with zero Objective-C compiler flags and zero -framework linker flags.

    BindlessHeap

    pub struct BindlessHeap {
    raw : UInt64
    }

    BindlessHeap::create

    fn BindlessHeap::create(dev : Device, capacity : Int) -> BindlessHeap?

    BindlessHeap::destroy

    fn BindlessHeap::destroy(self : BindlessHeap) -> Unit

    BindlessHeap::register_texture

    fn BindlessHeap::register_texture(self : BindlessHeap, tex : Texture, smp : Sampler) -> Int

    BindlessHeap::unregister_texture

    fn BindlessHeap::unregister_texture(self : BindlessHeap, slot : Int) -> Unit

    Buffer

    pub struct Buffer {
    raw : UInt64
    }

    Buffer::create

    fn Buffer::create(dev : Device, size : Int, storage_mode? : Int) -> Buffer?

    Buffer::destroy

    fn Buffer::destroy(self : Buffer) -> Unit

    Buffer::download

    fn Buffer::download(self : Buffer, out : FixedArray[Byte], len : Int) -> Bool

    Buffer::upload

    fn Buffer::upload(self : Buffer, data : Bytes, offset : Int, len : Int) -> Bool

    Buffer::upload_floats

    fn Buffer::upload_floats(self : Buffer, data : FixedArray[Float], offset_bytes : Int, count : Int) -> Bool

    CommandBuffer

    pub struct CommandBuffer {
    raw : UInt64
    }

    CommandBuffer::barrier

    fn CommandBuffer::barrier(self : CommandBuffer) -> Unit

    CommandBuffer::begin

    fn CommandBuffer::begin(dev : Device) -> CommandBuffer?

    CommandBuffer::begin_render_pass

    fn CommandBuffer::begin_render_pass(self : CommandBuffer, color_texs : FixedArray[UInt64], resolve_texs : FixedArray[UInt64], color_load_ops : FixedArray[Int], color_store_ops : FixedArray[Int], clear_rgba : FixedArray[Float], color_layers : FixedArray[Int], color_mips : FixedArray[Int], color_count : Int, depth_tex : UInt64, depth_load : Int, depth_store : Int, clear_depth : Float, stencil_load : Int, stencil_store : Int, clear_stencil : UInt, depth_layer : Int, depth_mip : Int) -> Bool

    CommandBuffer::begin_swapchain_pass

    fn CommandBuffer::begin_swapchain_pass(self : CommandBuffer, sc : Swapchain, load_op : Int, r : Float, g : Float, b : Float, a : Float) -> Bool

    CommandBuffer::bind_bindless

    fn CommandBuffer::bind_bindless(self : CommandBuffer, heap : BindlessHeap, is_compute : Bool) -> Unit

    CommandBuffer::bind_buffer

    fn CommandBuffer::bind_buffer(self : CommandBuffer, binding : Int, buf : Buffer, offset : Int, is_compute : Bool) -> Unit

    CommandBuffer::bind_compute_pipeline

    fn CommandBuffer::bind_compute_pipeline(self : CommandBuffer, pipe : ComputePipeline) -> Unit

    CommandBuffer::bind_index

    fn CommandBuffer::bind_index(self : CommandBuffer, buf : Buffer, is_u32 : Bool, offset : Int) -> Unit

    CommandBuffer::bind_render_pipeline

    fn CommandBuffer::bind_render_pipeline(self : CommandBuffer, pipe : RenderPipeline) -> Unit

    CommandBuffer::bind_texture

    fn CommandBuffer::bind_texture(self : CommandBuffer, binding : Int, tex : Texture, smp_raw : UInt64, is_compute : Bool) -> Unit

    CommandBuffer::bind_vertex

    fn CommandBuffer::bind_vertex(self : CommandBuffer, slot : Int, buf : Buffer, offset : Int) -> Unit

    CommandBuffer::blit_texture

    fn CommandBuffer::blit_texture(self : CommandBuffer, src : Texture, dst : Texture, linear : Bool) -> Bool

    CommandBuffer::blit_to_swapchain

    fn CommandBuffer::blit_to_swapchain(self : CommandBuffer, src : Texture, sc : Swapchain) -> Bool

    CommandBuffer::copy_buffer

    fn CommandBuffer::copy_buffer(self : CommandBuffer, src : Buffer, dst : Buffer, bytes : Int) -> Unit

    CommandBuffer::dispatch

    fn CommandBuffer::dispatch(self : CommandBuffer, gx : Int, gy : Int, gz : Int) -> Unit

    CommandBuffer::dispatch_indirect

    fn CommandBuffer::dispatch_indirect(self : CommandBuffer, buf : Buffer, offset : Int) -> Unit

    CommandBuffer::draw

    fn CommandBuffer::draw(self : CommandBuffer, vertex_count : Int, instance_count : Int, first_vertex : Int, first_instance : Int) -> Unit

    CommandBuffer::draw_indexed

    fn CommandBuffer::draw_indexed(self : CommandBuffer, index_count : Int, instance_count : Int, first_index : Int, vertex_offset : Int, first_instance : Int) -> Unit

    CommandBuffer::draw_indexed_indirect

    fn CommandBuffer::draw_indexed_indirect(self : CommandBuffer, buf : Buffer, offset : Int, draw_count : Int, stride : Int) -> Unit

    CommandBuffer::draw_indexed_indirect_count

    fn CommandBuffer::draw_indexed_indirect_count(self : CommandBuffer, buf : Buffer, count_buf : Buffer, offset : Int, count_offset : Int, max_draws : Int, stride : Int) -> Unit

    CommandBuffer::draw_indirect

    fn CommandBuffer::draw_indirect(self : CommandBuffer, buf : Buffer, offset : Int, draw_count : Int, stride : Int) -> Unit

    CommandBuffer::draw_indirect_count

    fn CommandBuffer::draw_indirect_count(self : CommandBuffer, buf : Buffer, count_buf : Buffer, offset : Int, count_offset : Int, max_draws : Int, stride : Int) -> Unit

    CommandBuffer::end_render_pass

    fn CommandBuffer::end_render_pass(self : CommandBuffer) -> Unit

    CommandBuffer::end_wait

    fn CommandBuffer::end_wait(self : CommandBuffer) -> Bool

    CommandBuffer::push_constants

    fn CommandBuffer::push_constants(self : CommandBuffer, data : Bytes, len : Int, is_compute : Bool) -> Unit

    CommandBuffer::push_constants_floats

    fn CommandBuffer::push_constants_floats(self : CommandBuffer, data : FixedArray[Float], count : Int, is_compute : Bool) -> Unit

    CommandBuffer::set_scissor

    fn CommandBuffer::set_scissor(self : CommandBuffer, x : Int, y : Int, w : Int, h : Int) -> Unit

    CommandBuffer::set_stencil_reference

    fn CommandBuffer::set_stencil_reference(self : CommandBuffer, ref_val : Int) -> Unit

    CommandBuffer::set_viewport

    fn CommandBuffer::set_viewport(self : CommandBuffer, x : Float, y : Float, w : Float, h : Float) -> Unit

    CommandBuffer::submit_async

    fn CommandBuffer::submit_async(self : CommandBuffer, fence : Fence) -> Bool

    CommandBuffer::write_timestamp

    fn CommandBuffer::write_timestamp(self : CommandBuffer, pool : TimestampPool, index : Int, is_end : Bool) -> Unit

    ComputePipeline

    pub struct ComputePipeline {
    raw : UInt64
    }

    ComputePipeline::create

    fn ComputePipeline::create(dev : Device, cs_words : FixedArray[UInt], local_x : Int, local_y : Int, local_z : Int) -> ComputePipeline?

    ComputePipeline::destroy

    fn ComputePipeline::destroy(self : ComputePipeline) -> Unit

    Device

    pub struct Device {
    raw : UInt64
    }

    Device::active_allocs

    fn Device::active_allocs(self : Device) -> Int

    Device::caps

    fn Device::caps(self : Device) -> DeviceCaps

    Device::create

    fn Device::create(validation? : Bool) -> Device?

    Device::destroy

    fn Device::destroy(self : Device) -> Unit

    Device::used_bytes

    fn Device::used_bytes(self : Device) -> UInt64

    Device::validation_errors

    fn Device::validation_errors(self : Device) -> Int

    Device::wait_idle

    fn Device::wait_idle(self : Device) -> Unit

    DeviceCaps

    pub(all) struct DeviceCaps {
    name : String
    is_discrete : Bool
    arg_buf_tier : Int
    d24s8_supported : Bool
    max_samples : Int
    supports_raytracing : Bool
    supports_mesh : Bool
    max_dim_2d : Int
    max_anisotropy : Int
    }

    Fence

    pub struct Fence {
    raw : UInt64
    }

    Fence::create

    fn Fence::create(signaled : Bool) -> Fence?

    Fence::destroy

    fn Fence::destroy(self : Fence) -> Unit

    Fence::reset

    fn Fence::reset(self : Fence) -> Unit

    Fence::wait

    fn Fence::wait(self : Fence) -> Unit

    RenderPipeline

    pub struct RenderPipeline {
    raw : UInt64
    }

    RenderPipeline::create

    fn RenderPipeline::create(dev : Device, vs_words : FixedArray[UInt], fs_words : FixedArray[UInt], vs_entry : String, fs_entry : String, state : FixedArray[Int], bias_const : Float, bias_slope : Float, color_formats : FixedArray[Int], blend_params : FixedArray[Int], vtx_layouts : FixedArray[Int], vtx_attrs : FixedArray[Int]) -> RenderPipeline?

    RenderPipeline::destroy

    fn RenderPipeline::destroy(self : RenderPipeline) -> Unit

    Sampler

    pub struct Sampler {
    raw : UInt64
    }

    Sampler::create

    fn Sampler::create(dev : Device, min_linear : Bool, mag_linear : Bool, mip_linear : Bool, addr_u : Int, addr_v : Int, addr_w : Int, border_color : Int, max_aniso : Float, min_lod : Float, max_lod : Float, compare_op : Int) -> Sampler?

    Sampler::destroy

    fn Sampler::destroy(self : Sampler) -> Unit

    Swapchain

    pub struct Swapchain {
    raw : UInt64
    }

    Swapchain::begin_frame

    fn Swapchain::begin_frame(self : Swapchain, begin_pass : Bool, r : Float, g : Float, b : Float, a : Float) -> CommandBuffer?

    Swapchain::create

    fn Swapchain::create(dev : Device, layer : UInt64, width : Int, height : Int, has_depth : Bool, depth_format : Int, enable_readback : Bool, vsync : Bool) -> Swapchain?

    Swapchain::destroy

    fn Swapchain::destroy(self : Swapchain) -> Unit

    Swapchain::end_frame

    fn Swapchain::end_frame(self : Swapchain, cmd : CommandBuffer) -> Bool

    Swapchain::present_texture

    fn Swapchain::present_texture(self : Swapchain, tex : Texture) -> Bool

    Swapchain::readback

    fn Swapchain::readback(self : Swapchain, out : FixedArray[Byte]) -> Bool

    Swapchain::resize

    fn Swapchain::resize(self : Swapchain, width : Int, height : Int) -> Bool

    Texture

    pub struct Texture {
    raw : UInt64
    }

    Texture::create

    fn Texture::create(dev : Device, width : Int, height : Int, format_code : Int, mip_levels? : Int, layers? : Int, samples? : Int, is_cube? : Bool, usage_bits? : Int) -> Texture?

    Texture::destroy

    fn Texture::destroy(self : Texture) -> Unit

    Texture::generate_mipmaps

    fn Texture::generate_mipmaps(self : Texture) -> Bool

    Texture::readback

    fn Texture::readback(self : Texture, mip : Int, layer : Int, out : FixedArray[Byte]) -> Bool

    Texture::upload_region

    fn Texture::upload_region(self : Texture, x : Int, y : Int, w : Int, h : Int, layer : Int, mip : Int, data : Bytes) -> Bool

    TimestampPool

    pub struct TimestampPool {
    raw : UInt64
    }

    TimestampPool::create

    fn TimestampPool::create(count : Int) -> TimestampPool?

    TimestampPool::destroy

    fn TimestampPool::destroy(self : TimestampPool) -> Unit

    TimestampPool::read

    fn TimestampPool::read(self : TimestampPool, out : FixedArray[Double]) -> Unit

    is_available

    fn is_available() -> Bool

    last_error

    fn last_error() -> String

    Source Files