heroseh / hcc

C Compiler to SPIR-V
MIT License
306 stars 11 forks source link

Hero C Compiler

HCC is a C compiler that allows you to compile your C codebase (with limitations) to SPIR-V for the Vulkan graphics API. This means you can share struct's, enum's and functions between your CPU & GPU code. HCC targets the future of GPU programming so is designed around features such as bindless resources and scalar alignment. This makes it easier to interop with the GPU and focus on writing shader code without writing your own shader build system.

The project is currently in alpha, so expect bugs and please help by filing bugs and contributing back to the codebase :)

Features

Limitations

What does it look like?

Here is a vertex & pixel shader triangle sample:

typedef struct Vertex Vertex;
struct Vertex {
    f32x2    pos;
    uint32_t color;
};

typedef struct TriangleBC TriangleBC;
struct TriangleBC {
    HccRoBuffer(Vertex) vertices;
    f32x4               tint;
};

typedef struct RasterizerState RasterizerState;
HCC_RASTERIZER_STATE struct RasterizerState {
    HCC_INTERP f32x4 color;
};

HCC_VERTEX void triangle_vs(
    HccVertexSV const* const sv,
    HccVertexSVOut* const sv_out,
    TriangleBC const* const bc,
    RasterizerState* const state_out
) {
    Vertex vertex = bc->vertices[sv->vertex_idx];

    sv_out->position = f32x4(vertex.pos.x, vertex.pos.y, 0.f, 1.f);
    state_out->color = mulG(unpack_u8x4_f32x4(vertex.color), bc->tint);
}

typedef struct Pixel Pixel;
HCC_PIXEL_STATE struct Pixel {
    f32x4 color;
};

HCC_PIXEL void triangle_ps(
    HccPixelSV const* const sv,
    HccPixelSVOut* const sv_out,
    TriangleBC const* const bc,
    RasterizerState const* const state,
    Pixel* const pixel_out
) {
    pixel_out->color = state->color;
}

Great, how do I find out more?

You can download the latest release here:

We also have the documentation you can check out here

Support

If enjoy using the project, please consider sending a tip to show your support. Thank you! :)

FAQ

Community

We have a Discord community for any HCC discussion or to be involved in a low-level C / Gamedev / Graphics community

Catch live development on the compiler at Twitch

Contributor

If you like the project and are a competent C programmer, please consider being a contributor. Join the Discord or open up some Github issues related to the features you want to work on.