Tycho RHI — unified pure-MoonBit render hardware interface (Vulkan 1.3 backend + DX12 backend seam; Metal planned)
moon add laplaceliu/tychopub suberror RhiError {
InitFailed(String)
DeviceFailed(String)
SwapchainFailed(String)
PipelineFailed(String)
AllocationFailed(String)
CommandFailed(String)
InvalidArgument(String)
BackendUnsupported(String)
}pub struct AccelStruct {
// private fields
}pub(all) struct BindGroup {
// private fields
}fn BindGroup::accel(self : BindGroup, pipeline : Pipeline, slot : Int, accel : AccelStruct) -> BindGrouppub struct BindlessHeap {
// private fields
}fn BindlessHeap::register_texture(self : BindlessHeap, texture : Texture, sampler : Sampler) -> Int raise RhiErrorpub(all) struct BlendState {
src_color : BlendFactor
dst_color : BlendFactor
color_op : BlendOp
src_alpha : BlendFactor
dst_alpha : BlendFactor
alpha_op : BlendOp
} derive(Eq, Debug)fn BlendState::new(src_color : BlendFactor, dst_color : BlendFactor, src_alpha : BlendFactor, dst_alpha : BlendFactor, color_op? : BlendOp, alpha_op? : BlendOp) -> BlendStatepub struct Buffer {
// private fields
}pub(all) struct BufferUsage {
// private fields
}pub(all) struct ClearColor {
r : Float
g : Float
b : Float
a : Float
}pub(all) struct ColorTargetState {
format : TextureFormat?
write : Bool
blend_mode : BlendMode?
blend_state : BlendState?
}fn ColorTargetState::new(format? : TextureFormat, write? : Bool, blend_mode? : BlendMode, blend_state? : BlendState) -> ColorTargetStatepub 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_accel_struct(self : CommandBuffer, pipeline : Pipeline, slot : Int, accel : AccelStruct) -> 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, offset? : Int, size? : Int) -> 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, offset? : Int, size? : Int) -> 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::compute_pass(self : CommandBuffer, encode : (ComputePass) -> Unit raise RhiError) -> Unit raise RhiErrorfn 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_indexed_indirect_count(self : CommandBuffer, buffer : Buffer, count_buffer : Buffer, max_draw_count : Int, offset? : Int, count_offset? : Int, stride? : Int) -> Unitfn CommandBuffer::draw_indirect(self : CommandBuffer, buffer : Buffer, draw_count : Int, offset? : Int, stride? : Int) -> Unitfn CommandBuffer::draw_indirect_count(self : CommandBuffer, buffer : Buffer, count_buffer : Buffer, max_draw_count : Int, offset? : Int, count_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::push_constants_mat4(self : CommandBuffer, pipeline : Pipeline, m : Mat4, offset? : Int) -> Unitfn CommandBuffer::render_pass(self : CommandBuffer, colors : Array[RenderTargetDesc], depth? : DepthTargetDesc, draw : (RenderPass) -> Unit raise RhiError) -> Unit raise RhiErrorfn CommandBuffer::set_viewport(self : CommandBuffer, x : Float, y : Float, w : Float, h : Float) -> Unitfn CommandBuffer::swapchain_pass(self : CommandBuffer, swapchain : Swapchain, load_op? : LoadOp, clear_color? : ClearColor, draw : (RenderPass) -> Unit raise RhiError) -> Unit raise RhiErrorfn CommandBuffer::write_timestamp(self : CommandBuffer, pool : TimestampPool, index : Int, at_start? : Bool) -> Unitpub struct ComputePass {
// private fields
}fn ComputePass::bind_bindless_heap(self : ComputePass, pipeline : Pipeline, heap : BindlessHeap, set_index? : Int) -> Unitfn ComputePass::bind_storage(self : ComputePass, pipeline : Pipeline, slot : Int, buffer : Buffer, offset? : Int, size? : Int) -> Unitfn ComputePass::bind_storage_image(self : ComputePass, pipeline : Pipeline, slot : Int, texture : Texture) -> Unitfn ComputePass::bind_uniform(self : ComputePass, pipeline : Pipeline, slot : Int, buffer : Buffer, offset? : Int, size? : Int) -> Unitfn ComputePass::push_constants_bytes(self : ComputePass, pipeline : Pipeline, data : Bytes, offset? : Int) -> Unitfn ComputePass::push_constants_floats(self : ComputePass, pipeline : Pipeline, data : FixedArray[Float], offset? : Int) -> Unitfn ComputePass::write_timestamp(self : ComputePass, pool : TimestampPool, index : Int, at_start? : Bool) -> Unitpub(all) struct DepthStencilState {
depth_test : Bool
write : Bool
compare : CompareOp
format : TextureFormat?
depth_only : Bool
bias : Bool
bias_constant : Float
bias_slope : Float
stencil : StencilState?
}fn DepthStencilState::new(depth_test? : Bool, write? : Bool, compare? : CompareOp, format? : TextureFormat, depth_only? : Bool, bias? : Bool, bias_constant? : Float, bias_slope? : Float, stencil? : StencilState) -> DepthStencilStatefn DepthTargetDesc::new(texture : Texture, load_op? : LoadOp, store_op? : StoreOp, clear_depth? : Float, stencil_load_op? : LoadOp, stencil_store_op? : StoreOp, clear_stencil? : Int) -> DepthTargetDescpub struct Device {
// private fields
}fn Device::create_blas(self : Device, geometries : Array[RayGeometryDesc]) -> AccelStruct raise RhiErrorfn Device::create_buffer_usage(self : Device, size : Int, usage : BufferUsage, location? : MemoryLocation) -> Buffer raise RhiErrorfn 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_desc(self : Device, desc : TextureDesc, data? : 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::create_tlas(self : Device, instances : Array[RayInstanceDesc]) -> AccelStruct 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
backend : BackendKind
}fn DeviceDesc::new(app_name : String, validation? : Bool, headless? : Bool, pipeline_cache? : Bytes, backend? : BackendKind) -> 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
raster : RasterState
depth_stencil : DepthStencilState?
color_targets : Array[ColorTargetState]
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, color_write? : Bool, 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
accel_slots : Int
uniform_bindings : Array[Int]
texture_bindings : Array[Int]
storage_bindings : Array[Int]
storage_image_bindings : Array[Int]
accel_bindings : Array[Int]
push_constant_size : Int
raster : RasterState
depth_stencil : DepthStencilState?
color_targets : Array[ColorTargetState]
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, stencil? : StencilState, cull_mode? : CullMode, front_face? : FrontFace, blend? : Bool, blend_mode? : BlendMode, blend_state? : BlendState, color_write? : Bool, samples? : SampleCount, color_format? : TextureFormat, color_formats? : Array[TextureFormat], vertex_layouts? : Array[VertexBufferLayout], bindless_heap? : BindlessHeap) -> PipelineDescfn PipelineDesc::graphics(vert : FixedArray[UInt], frag : FixedArray[UInt], vert_entry? : String, frag_entry? : String, raster? : RasterState, depth_stencil? : DepthStencilState, color_targets? : Array[ColorTargetState], vertex_formats? : Array[VertexFormat], vertex_layouts? : Array[VertexBufferLayout], uniform_slots? : Int, texture_slots? : Int, storage_slots? : Int, storage_image_slots? : Int, accel_slots? : Int, uniform_bindings? : Array[Int], texture_bindings? : Array[Int], storage_bindings? : Array[Int], storage_image_bindings? : Array[Int], accel_bindings? : Array[Int], push_constant_size? : Int, 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, accel_slots? : Int, uniform_bindings? : Array[Int], texture_bindings? : Array[Int], storage_bindings? : Array[Int], storage_image_bindings? : Array[Int], accel_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, stencil? : StencilState, cull_mode? : CullMode, front_face? : FrontFace, blend? : Bool, blend_mode? : BlendMode, blend_state? : BlendState, color_write? : Bool, samples? : SampleCount, color_format? : TextureFormat, color_formats? : Array[TextureFormat], bindless_heap? : BindlessHeap) -> PipelineDescpub(all) struct RasterState {
topology : PrimitiveTopology
cull_mode : CullMode
front_face : FrontFace
samples : SampleCount
}fn RasterState::new(topology? : PrimitiveTopology, cull_mode? : CullMode, front_face? : FrontFace, samples? : SampleCount) -> RasterStatefn RayGeometryDesc::new(vertex_buffer : Buffer, vertex_count : Int, vertex_stride? : Int, index_buffer? : Buffer, index_count? : Int, index_type? : IndexType, is_opaque? : Bool) -> RayGeometryDescpub(all) struct RayInstanceDesc {
blas : AccelStruct
transform : FixedArray[Float]
custom_index : Int
mask : Int
}fn RayInstanceDesc::from_affine3(blas : AccelStruct, affine : Affine3, custom_index? : Int, mask? : Int) -> RayInstanceDescfn RayInstanceDesc::new(blas : AccelStruct, transform? : FixedArray[Float], custom_index? : Int, mask? : Int) -> RayInstanceDescpub struct RenderPass {
// private fields
}fn RenderPass::bind_accel_struct(self : RenderPass, pipeline : Pipeline, slot : Int, accel : AccelStruct) -> Unitfn RenderPass::bind_bindless_heap(self : RenderPass, pipeline : Pipeline, heap : BindlessHeap, set_index? : Int) -> Unitfn RenderPass::bind_index(self : RenderPass, buffer : Buffer, index_type : IndexType, offset? : Int) -> Unitfn RenderPass::bind_storage(self : RenderPass, pipeline : Pipeline, slot : Int, buffer : Buffer, offset? : Int, size? : Int) -> Unitfn RenderPass::bind_texture(self : RenderPass, pipeline : Pipeline, slot : Int, texture : Texture, sampler : Sampler) -> Unitfn RenderPass::bind_uniform(self : RenderPass, pipeline : Pipeline, slot : Int, buffer : Buffer, offset? : Int, size? : Int) -> Unitfn RenderPass::draw_indexed_full(self : RenderPass, index_count : Int, instances : Int, first_index : Int, vertex_offset : Int, first_instance : Int) -> Unitfn RenderPass::draw_indexed_indirect(self : RenderPass, buffer : Buffer, draw_count : Int, offset? : Int, stride? : Int) -> Unitfn RenderPass::draw_indexed_indirect_count(self : RenderPass, buffer : Buffer, count_buffer : Buffer, max_draw_count : Int, offset? : Int, count_offset? : Int, stride? : Int) -> Unitfn RenderPass::draw_indirect(self : RenderPass, buffer : Buffer, draw_count : Int, offset? : Int, stride? : Int) -> Unitfn RenderPass::draw_indirect_count(self : RenderPass, buffer : Buffer, count_buffer : Buffer, max_draw_count : Int, offset? : Int, count_offset? : Int, stride? : Int) -> Unitfn RenderPass::draw_instanced(self : RenderPass, vertices : Int, instances : Int, first_vertex : Int, first_instance : Int) -> Unitfn RenderPass::push_constants_bytes(self : RenderPass, pipeline : Pipeline, data : Bytes, offset? : Int) -> Unitfn RenderPass::push_constants_floats(self : RenderPass, pipeline : Pipeline, data : FixedArray[Float], offset? : Int) -> Unitpub(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) -> SamplerDescfn StencilFaceState::new(fail_op? : StencilOp, pass_op? : StencilOp, depth_fail_op? : StencilOp, compare_op? : CompareOp) -> StencilFaceStatepub(all) struct StencilState {
front : StencilFaceState
back : StencilFaceState
compare_mask : UInt
write_mask : UInt
reference : UInt
}fn StencilState::new(front? : StencilFaceState, back? : StencilFaceState, compare_mask? : UInt, write_mask? : UInt, reference? : UInt) -> StencilStatepub 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
depth_format : TextureFormat
clear_color : ClearColor
enable_readback : Bool
present_mode : PresentMode
}fn SwapchainDesc::new(title : String, width : Int, height : Int, depth? : Bool, depth_format? : TextureFormat, clear_color? : ClearColor, enable_readback? : Bool, present_mode? : PresentMode) -> SwapchainDescpub struct Texture {
// private fields
}pub(all) struct TextureDesc {
width : Int
height : Int
format : TextureFormat
usage : TextureUsage
dimension : TextureDimension
mip_levels : Int
samples : SampleCount
}fn TextureDesc::new(width : Int, height : Int, format : TextureFormat, usage? : TextureUsage, dimension? : TextureDimension, mip_levels? : Int, samples? : SampleCount) -> TextureDescpub(all) struct TextureUsage {
// 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 dx12_available() -> BoolInstall
Download zipTycho RHI — unified pure-MoonBit render hardware interface (Vulkan 1.3 backend + DX12 backend seam; Metal planned)