Tycho RHI — unified pure-MoonBit render hardware interface (Vulkan 1.3 dynamic rendering + sub-allocator; Metal/DX12 planned)
moon add laplaceliu/tycho// moon.pkg
options(
"link": {
"native": {
"cc": "cc",
"cc-link-flags": "-lvulkan -lX11", // -lX11 only needed for windowing/WSI
},
},
)pub suberror RhiError {
InitFailed(String)
DeviceFailed(String)
SwapchainFailed(String)
PipelineFailed(String)
AllocationFailed(String)
CommandFailed(String)
InvalidArgument(String)
}pub struct BindlessHeap {
// private fields
}fn BindlessHeap::register_texture(self : BindlessHeap, texture : Texture, sampler : Sampler) -> Int raise RhiErrorpub struct Buffer {
// private fields
}pub(all) struct ClearColor {
r : Float
g : Float
b : Float
a : Float
}pub struct CommandBuffer {
// private fields
}fn CommandBuffer::begin_render_pass(self : CommandBuffer, colors : Array[RenderTargetDesc], depth? : DepthTargetDesc?) -> Unit raise RhiErrorfn CommandBuffer::begin_swapchain_pass(self : CommandBuffer, swapchain : Swapchain, load_op? : LoadOp, clear_color? : ClearColor?) -> Unitfn CommandBuffer::bind_bindless_heap(self : CommandBuffer, pipeline : Pipeline, heap : BindlessHeap, set_index? : Int) -> Unitfn CommandBuffer::bind_index(self : CommandBuffer, buffer : Buffer, index_type : IndexType, offset? : Int) -> Unitfn CommandBuffer::bind_storage(self : CommandBuffer, pipeline : Pipeline, slot : Int, buffer : Buffer) -> Unitfn CommandBuffer::bind_storage_image(self : CommandBuffer, pipeline : Pipeline, slot : Int, texture : Texture) -> Unitfn CommandBuffer::bind_texture(self : CommandBuffer, pipeline : Pipeline, slot : Int, texture : Texture, sampler : Sampler) -> Unitfn CommandBuffer::bind_uniform(self : CommandBuffer, pipeline : Pipeline, slot : Int, buffer : Buffer) -> Unitfn CommandBuffer::bind_vertex(self : CommandBuffer, slot : Int, buffer : Buffer, offset? : Int) -> Unitfn CommandBuffer::blit_texture(self : CommandBuffer, src : Texture, dst : Texture, filter? : Filter) -> Unitfn CommandBuffer::blit_to_swapchain(self : CommandBuffer, src : Texture, swapchain : Swapchain) -> Unitfn CommandBuffer::draw_indexed_full(self : CommandBuffer, index_count : Int, instances : Int, first_index : Int, vertex_offset : Int, first_instance : Int) -> Unitfn CommandBuffer::draw_indexed_indirect(self : CommandBuffer, buffer : Buffer, draw_count : Int, offset? : Int, stride? : Int) -> Unitfn CommandBuffer::draw_indirect(self : CommandBuffer, buffer : Buffer, draw_count : Int, offset? : Int, stride? : Int) -> Unitfn CommandBuffer::draw_instanced(self : CommandBuffer, vertices : Int, instances : Int, first_vertex : Int, first_instance : Int) -> Unitfn CommandBuffer::draw_mesh_tasks_indirect(self : CommandBuffer, buffer : Buffer, draw_count : Int, offset? : Int, stride? : Int) -> Unitfn CommandBuffer::push_constants_bytes(self : CommandBuffer, pipeline : Pipeline, data : Bytes, offset? : Int) -> Unitfn CommandBuffer::push_constants_floats(self : CommandBuffer, pipeline : Pipeline, data : FixedArray[Float], offset? : Int) -> Unitfn CommandBuffer::set_viewport(self : CommandBuffer, x : Float, y : Float, w : Float, h : Float) -> Unitfn CommandBuffer::write_timestamp(self : CommandBuffer, pool : TimestampPool, index : Int, at_start? : Bool) -> Unitfn DepthTargetDesc::new(texture : Texture, load_op? : LoadOp, store_op? : StoreOp, clear_depth? : Float) -> DepthTargetDescpub struct Device {
// private fields
}fn Device::create_buffer_with(self : Device, size : Int, kind : BufferKind, location? : MemoryLocation) -> Buffer raise RhiErrorfn Device::create_depth_texture(self : Device, width : Int, height : Int, samples? : SampleCount) -> Texture raise RhiErrorfn Device::create_depth_texture_format(self : Device, width : Int, height : Int, format : TextureFormat, samples? : SampleCount) -> Texture raise RhiErrorfn Device::create_render_target(self : Device, width : Int, height : Int, format : TextureFormat, samples? : SampleCount) -> Texture raise RhiErrorfn Device::create_storage_texture(self : Device, width : Int, height : Int, format : TextureFormat) -> Texture raise RhiErrorfn Device::create_texture_array(self : Device, width : Int, height : Int, layers : Int, format : TextureFormat, pixels : Bytes) -> Texture raise RhiErrorfn Device::create_texture_format(self : Device, width : Int, height : Int, format : TextureFormat, pixels : Bytes) -> Texture raise RhiErrorfn Device::create_texture_mipmapped(self : Device, width : Int, height : Int, format : TextureFormat, pixels : Bytes) -> Texture raise RhiErrorfn Device::submit_commands(self : Device, cmd : CommandBuffer, fence : Fence) -> Unit raise RhiErrorpub(all) struct DeviceCapabilities {
device_name : String
is_discrete : Bool
api_version : UInt
driver_version : UInt
max_image_dimension_2d : Int
max_framebuffer_samples : Int
max_sampler_anisotropy : Float
supports_anisotropy : Bool
supports_indirect_draw : Bool
supports_bindless : Bool
supports_mesh_shader : Bool
supports_ray_query : Bool
}pub(all) struct DeviceDesc {
app_name : String
validation : Bool
headless : Bool
pipeline_cache : Bytes
}fn DeviceDesc::new(app_name : String, validation? : Bool, headless? : Bool, pipeline_cache? : Bytes) -> DeviceDescpub struct Fence {
// private fields
}pub(all) struct MeshPipelineDesc {
task : FixedArray[UInt]?
mesh : FixedArray[UInt]
frag : FixedArray[UInt]
task_entry : String
mesh_entry : String
frag_entry : String
uniform_slots : Int
texture_slots : Int
storage_slots : Int
storage_image_slots : Int
uniform_bindings : Array[Int]
texture_bindings : Array[Int]
storage_bindings : Array[Int]
storage_image_bindings : Array[Int]
push_constant_size : Int
depth_test : Bool
depth_write : Bool
depth_compare : CompareOp
depth_format : TextureFormat?
cull_mode : CullMode
front_face : FrontFace
blend : Bool
blend_mode : BlendMode?
samples : SampleCount
color_format : TextureFormat?
color_formats : Array[TextureFormat]
bindless_heap : BindlessHeap?
}fn MeshPipelineDesc::new(mesh : FixedArray[UInt], frag : FixedArray[UInt], task? : FixedArray[UInt]?, task_entry? : String, mesh_entry? : String, frag_entry? : String, uniform_slots? : Int, texture_slots? : Int, storage_slots? : Int, storage_image_slots? : Int, uniform_bindings? : Array[Int], texture_bindings? : Array[Int], storage_bindings? : Array[Int], storage_image_bindings? : Array[Int], push_constant_size? : Int, depth_test? : Bool, depth_write? : Bool, depth_compare? : CompareOp, depth_format? : TextureFormat?, cull_mode? : CullMode, front_face? : FrontFace, blend? : Bool, blend_mode? : BlendMode?, samples? : SampleCount, color_format? : TextureFormat?, color_formats? : Array[TextureFormat], bindless_heap? : BindlessHeap?) -> MeshPipelineDescpub struct Pipeline {
// private fields
}pub(all) struct PipelineDesc {
vert : FixedArray[UInt]
frag : FixedArray[UInt]
vert_entry : String
frag_entry : String
vertex_formats : Array[VertexFormat]
vertex_layouts : Array[VertexBufferLayout]
uniform_slots : Int
texture_slots : Int
storage_slots : Int
storage_image_slots : Int
uniform_bindings : Array[Int]
texture_bindings : Array[Int]
storage_bindings : Array[Int]
storage_image_bindings : Array[Int]
push_constant_size : Int
topology : PrimitiveTopology
depth_test : Bool
depth_write : Bool
depth_compare : CompareOp
depth_format : TextureFormat?
depth_only : Bool
depth_bias : Bool
depth_bias_constant : Float
depth_bias_slope : Float
cull_mode : CullMode
front_face : FrontFace
blend : Bool
blend_mode : BlendMode?
samples : SampleCount
color_format : TextureFormat?
color_formats : Array[TextureFormat]
bindless_heap : BindlessHeap?
}fn PipelineDesc::from_spirv(vert : FixedArray[UInt], frag : FixedArray[UInt], topology? : PrimitiveTopology, depth_test? : Bool, depth_write? : Bool, depth_compare? : CompareOp, depth_format? : TextureFormat?, depth_only? : Bool, depth_bias? : Bool, depth_bias_constant? : Float, depth_bias_slope? : Float, cull_mode? : CullMode, front_face? : FrontFace, blend? : Bool, blend_mode? : BlendMode?, samples? : SampleCount, color_format? : TextureFormat?, color_formats? : Array[TextureFormat], vertex_layouts? : Array[VertexBufferLayout], bindless_heap? : BindlessHeap?) -> PipelineDescfn PipelineDesc::new(vert : FixedArray[UInt], frag : FixedArray[UInt], vert_entry? : String, frag_entry? : String, vertex_formats? : Array[VertexFormat], vertex_layouts? : Array[VertexBufferLayout], uniform_slots? : Int, texture_slots? : Int, storage_slots? : Int, storage_image_slots? : Int, uniform_bindings? : Array[Int], texture_bindings? : Array[Int], storage_bindings? : Array[Int], storage_image_bindings? : Array[Int], push_constant_size? : Int, topology? : PrimitiveTopology, depth_test? : Bool, depth_write? : Bool, depth_compare? : CompareOp, depth_format? : TextureFormat?, depth_only? : Bool, depth_bias? : Bool, depth_bias_constant? : Float, depth_bias_slope? : Float, cull_mode? : CullMode, front_face? : FrontFace, blend? : Bool, blend_mode? : BlendMode?, samples? : SampleCount, color_format? : TextureFormat?, color_formats? : Array[TextureFormat], bindless_heap? : BindlessHeap?) -> PipelineDescpub(all) struct RenderTargetDesc {
texture : Texture
load_op : LoadOp
store_op : StoreOp
clear_color : ClearColor
resolve_texture : Texture?
}fn RenderTargetDesc::new(texture : Texture, load_op? : LoadOp, store_op? : StoreOp, clear_color? : ClearColor, resolve_texture? : Texture?) -> RenderTargetDescpub struct Sampler {
// private fields
}pub(all) struct SamplerDesc {
mag : Filter
min : Filter
mipmap : Filter
address : AddressMode
border_color : BorderColor
min_lod : Float
max_lod : Float
mip_lod_bias : Float
anisotropy : Float
compare_op : CompareOp?
}fn SamplerDesc::new(mag? : Filter, min? : Filter, mipmap? : Filter, address? : AddressMode, border_color? : BorderColor, min_lod? : Float, max_lod? : Float, mip_lod_bias? : Float, anisotropy? : Float, compare_op? : CompareOp?) -> SamplerDescpub struct Swapchain {
// private fields
}fn Swapchain::create_mesh_pipeline(self : Swapchain, desc : MeshPipelineDesc) -> Pipeline raise RhiErrorfn Swapchain::create_pipeline_desc(self : Swapchain, desc : PipelineDesc) -> Pipeline raise RhiErrorpub(all) struct SwapchainDesc {
title : String
width : Int
height : Int
depth : Bool
clear_color : ClearColor
enable_readback : Bool
present_mode : PresentMode
}fn SwapchainDesc::new(title : String, width : Int, height : Int, depth? : Bool, clear_color? : ClearColor, enable_readback? : Bool, present_mode? : PresentMode) -> SwapchainDescpub struct Texture {
// private fields
}pub struct TimestampPool {
// private fields
}fn TimestampPool::elapsed_ms(self : TimestampPool, start_idx : Int, end_idx : Int) -> Double raise RhiErrorpub(all) struct VertexBufferLayout {
stride : Int
step_mode : VertexStepMode
attributes : Array[VertexAttribute]
}fn VertexBufferLayout::new(stride : Int, attributes : Array[VertexAttribute], step_mode? : VertexStepMode) -> VertexBufferLayoutfn save_png(path : String, width : Int, height : Int, rgba : FixedArray[Byte], bgra? : Bool) -> BoolInstall
Download zipTycho RHI — unified pure-MoonBit render hardware interface (Vulkan 1.3 dynamic rendering + sub-allocator; Metal/DX12 planned)