tycho_shader

    GLSL (glslangValidator) and Slang shader compilation, pure-MoonBit SPIR-V reflection, and PPM/BMP image loading helpers for Tycho

    vulkan
    shader
    spirv
    glslang
    slang
    tycho
    Download zip
    Version
    0.6.0
    License
    Apache-2.0
    Last updated
    3 hours ago
    Downloads
    27

    No dependencies

    #laplaceliu/tycho_shader

    Optional shader compilation and asset loading helpers for the Tycho graphics stack:

    • GLSL → SPIR-V compilation by invoking glslangValidator (compile_shader, compile_shader_file, compile_shader_env, compile_shader_file_env)
    • Slang → SPIR-V compilation by invoking slangc (compile_slang, compile_slang_file)
    • Binary .spv file loader (load_spirv)
    • Pure-MoonBit SPIR-V bytecode reflector (reflect_spirv — extracts stage, vertex inputs, descriptor bindings, push constant size, MRT output count with zero external C deps)
    • PPM (P6) / BMP image decoding to RGBA8 (load_image)

    Zero C link dependencies: compilers are resolved from TYCHO_GLSLANG / TYCHO_SLANGC, beside the executable, or on PATH; images are decoded by a bundled minimal loader. Decoupled from laplaceliu/tycho_vulkan, so core Vulkan users need neither libshaderc-dev nor libstb-dev.

    Runtime tools (only when you actually compile at runtime): glslangValidator (glslang-tools on Debian/Ubuntu) and, for Slang, slangc.

    ReflectedBinding

    pub(all) struct ReflectedBinding {
    set : Int
    binding : Int
    kind : ReflectedDescriptorKind
    count : Int
    name : String
    } derive(Eq,
    Debug
    )

    ReflectedDescriptorKind

    pub(all) enum ReflectedDescriptorKind {
    UniformBuffer
    StorageBuffer
    CombinedImageSampler
    StorageImage
    SampledImage
    Sampler
    } derive(Eq,
    Debug
    )

    ReflectedStage

    pub(all) enum ReflectedStage {
    Vertex
    Fragment
    Compute
    Unknown
    } derive(Eq,
    Debug
    )

    ReflectedVertexFormat

    pub(all) enum ReflectedVertexFormat {
    Float1
    Float2
    Float3
    Float4
    Int1
    Uint1
    Unknown
    } derive(Eq,
    Debug
    )

    ReflectedVertexInput

    pub(all) struct ReflectedVertexInput {
    location : Int
    format : ReflectedVertexFormat
    name : String
    } derive(Eq,
    Debug
    )

    SpirvReflection

    pub(all) struct SpirvReflection {
    stage : ReflectedStage
    entry_point : String
    vertex_inputs : Array[ReflectedVertexInput]
    bindings : Array[ReflectedBinding]
    push_constant_size : Int
    color_output_count : Int
    local_size : (Int, Int, Int)
    }

    SHADER_ENV_VULKAN_1_0

    let SHADER_ENV_VULKAN_1_0 : UInt

    SHADER_ENV_VULKAN_1_1

    let SHADER_ENV_VULKAN_1_1 : UInt

    SHADER_ENV_VULKAN_1_2

    let SHADER_ENV_VULKAN_1_2 : UInt

    SHADER_ENV_VULKAN_1_3

    let SHADER_ENV_VULKAN_1_3 : UInt

    SHADER_KIND_ANYHIT

    let SHADER_KIND_ANYHIT : UInt

    SHADER_KIND_CALLABLE

    let SHADER_KIND_CALLABLE : UInt

    SHADER_KIND_CLOSESTHIT

    let SHADER_KIND_CLOSESTHIT : UInt

    SHADER_KIND_COMPUTE

    let SHADER_KIND_COMPUTE : UInt

    SHADER_KIND_FRAGMENT

    let SHADER_KIND_FRAGMENT : UInt

    SHADER_KIND_INTERSECTION

    let SHADER_KIND_INTERSECTION : UInt

    SHADER_KIND_MESH

    let SHADER_KIND_MESH : UInt

    SHADER_KIND_MISS

    let SHADER_KIND_MISS : UInt

    SHADER_KIND_RAYGEN

    let SHADER_KIND_RAYGEN : UInt

    SHADER_KIND_TASK

    let SHADER_KIND_TASK : UInt

    SHADER_KIND_VERTEX

    let SHADER_KIND_VERTEX : UInt

    compile_shader

    fn compile_shader(source : String, kind : UInt) -> FixedArray[UInt]

    compile_shader_env

    fn compile_shader_env(source : String, kind : UInt, env : UInt) -> FixedArray[UInt]

    compile_shader_file

    fn compile_shader_file(path : String, kind : UInt) -> FixedArray[UInt]

    compile_shader_file_env

    fn compile_shader_file_env(path : String, kind : UInt, env : UInt) -> FixedArray[UInt]

    compile_slang

    fn compile_slang(source : String, entry : String) -> FixedArray[UInt]

    compile_slang_file

    fn compile_slang_file(path : String, entry : String) -> FixedArray[UInt]

    load_hdr_image

    fn load_hdr_image(path : String) -> (FixedArray[Float], Int, Int)

    load_image

    fn load_image(path : String) -> (FixedArray[Byte], Int, Int)

    load_spirv

    fn load_spirv(path : String) -> FixedArray[UInt]

    read_file_bytes

    fn read_file_bytes(path : String) -> Bytes

    reflect_spirv

    fn reflect_spirv(spv : FixedArray[UInt]) -> SpirvReflection

    save_png

    fn save_png(path : String, width : Int, height : Int, rgba : FixedArray[Byte], bgra? : Bool) -> Bool

    screenshot_path

    fn screenshot_path() -> String

    want_window

    fn want_window() -> Bool