moonbitstack/moonwgpu/hal does not have a README file

    Hal

    pub(open) trait Hal {
    fn name(Self) -> String
    fn limits(Self) ->
    Limits

    fn features(Self) ->
    Features

    fn create_buffer(Self,
    BufferDescriptor
    ) ->
    BufferId
    raise HalError
    fn destroy_buffer(Self,
    BufferId
    ) -> Unit
    fn write_buffer(Self,
    BufferId
    , Int, Bytes) -> Unit raise HalError
    fn read_buffer(Self,
    BufferId
    , Int, Int) -> Bytes raise HalError
    fn create_texture(Self,
    TextureDescriptor
    ) ->
    TextureId
    raise HalError
    fn destroy_texture(Self,
    TextureId
    ) -> Unit
    fn create_texture_view(Self,
    TextureId
    ,
    TextureViewDescriptor
    ) ->
    TextureViewId
    raise HalError
    fn create_sampler(Self,
    SamplerDescriptor
    ) ->
    SamplerId
    raise HalError
    fn create_shader_module(Self,
    ShaderModuleDescriptor
    ) ->
    ShaderModuleId
    raise HalError
    fn compilation_info(Self,
    ShaderModuleId
    ) -> Array[
    CompilationMessage
    ]
    fn create_bind_group_layout(Self,
    BindGroupLayoutDescriptor
    ) ->
    BindGroupLayoutId
    raise HalError
    fn create_bind_group(Self,
    BindGroupDescriptor
    ) ->
    BindGroupId
    raise HalError
    fn create_pipeline_layout(Self,
    PipelineLayoutDescriptor
    ) ->
    PipelineLayoutId
    raise HalError
    fn create_render_pipeline(Self,
    RenderPipelineDescriptor
    ) ->
    RenderPipelineId
    raise HalError
    fn create_compute_pipeline(Self,
    ComputePipelineDescriptor
    ) ->
    ComputePipelineId
    raise HalError
    fn create_query_set(Self,
    QuerySetDescriptor
    ) ->
    QuerySetId
    raise HalError
    fn create_external_texture(Self,
    ExternalTextureDescriptor
    ) ->
    ExternalTextureId
    raise HalError
    fn destroy_external_texture(Self,
    ExternalTextureId
    ) -> Unit
    fn submit(Self, Array[
    Command
    ]) -> Unit raise HalError
    fn read_texture(Self,
    TextureId
    ,
    Origin3d
    ,
    Extent3d
    , Int) -> Bytes raise HalError
    fn write_texture(Self,
    TextureId
    ,
    Origin3d
    ,
    Extent3d
    , Int, Bytes) -> Unit raise HalError
    }

    What a backend has to provide.

    The methods mirror the specification's device-timeline steps one for one: a resource is created here only after the layer above has validated the descriptor, so an implementation may assume its arguments are legal. The two exceptions are the byte-level operations, which receive whatever the caller asked for and report what they cannot do.

    Nothing here knows about pipelines beyond storing them: compiling WGSL is the job of the shader compiler a backend is handed, and a backend without one still records the pipeline so that command buffers replay exactly.

    Surface

    pub(open) trait Surface {
    fn name(Self) -> String
    fn size(Self) ->
    Extent3d

    fn configure(Self,
    SurfaceConfiguration
    ) -> Unit raise HalError
    fn unconfigure(Self) -> Unit
    fn capabilities(Self) ->
    SurfaceCapabilities

    fn acquire(Self) ->
    SurfaceFrame
    raise HalError
    fn present(Self,
    TextureId
    ) -> Unit raise HalError
    }

    What a host has to provide for a canvas to exist.

    Presentation is the one part of the WebGPU object graph that cannot be written without a window system, so it is a contract instead of an implementation: a windowing layer implements this trait over its own surface handle and hands it to CanvasContext. Nothing about a swap chain, a compositor or a display server appears above this line.

    The frames belong to the surface, not to the device: acquire returns a texture identity that the same surface presents and recycles, which is why present is here and not on Hal.

    HalError

    pub suberror HalError {
    Missing(what~ : String)
    Unsupported(what~ : String)
    Exhausted(want~ : Int, limit~ : Int)
    Failed(what~ : String)
    }

    Why a backend could not do what it was asked.

    A backend reports only what it knows: a resource it does not have, an operation it does not implement, or a host that ran out of memory. Whether a request is valid is decided before the backend is called, by core.

    HalError::exhausted

    fn HalError::exhausted(want : Int, limit : Int) -> HalError

    HalError::failed

    fn HalError::failed(what : String) -> HalError

    HalError::missing

    fn HalError::missing(what : String) -> HalError

    HalError::unsupported

    fn HalError::unsupported(what : String) -> HalError

    Unbound

    pub struct Unbound {
    name_ : String
    reason_ : String
    }

    A backend that is named but not bound.

    Every graphics API needs a stub of C functions before MoonBit can call it, and a platform needs a window before it can present. Until that stub exists, a backend still has to be a name: this is it. It carries the name of the API it stands for and the reason it cannot work, and refuses every call with that reason, so that code written against a real backend compiles and fails where it should instead of at the wrong layer.

    It is also the honest way to test error routing: a refusal from here passes through the same path a driver failure does.
    impl Hal for Unbound

    Unbound::new

    fn Unbound::new(name~ : String, reason? : String) -> Unbound

    A backend name without a binding.

    Unbound::reason

    fn Unbound::reason(self : Unbound) -> String

    What is missing.