{"id":13731910,"url":"https://github.com/garettbass/gpuc","last_synced_at":"2025-05-08T05:31:45.302Z","repository":{"id":88957341,"uuid":"202178670","full_name":"garettbass/gpuc","owner":"garettbass","description":"A header-only C-like shading language compiler that writes Metal, HLSL, GLSL","archived":false,"fork":false,"pushed_at":"2019-08-13T16:01:54.000Z","size":40,"stargazers_count":60,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T00:13:00.487Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/garettbass.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-13T15:59:15.000Z","updated_at":"2024-06-13T08:08:47.000Z","dependencies_parsed_at":"2023-06-13T08:00:14.807Z","dependency_job_id":null,"html_url":"https://github.com/garettbass/gpuc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garettbass%2Fgpuc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garettbass%2Fgpuc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garettbass%2Fgpuc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garettbass%2Fgpuc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garettbass","download_url":"https://codeload.github.com/garettbass/gpuc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253008791,"owners_count":21839700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:41.240Z","updated_at":"2025-05-08T05:31:45.288Z","avatar_url":"https://github.com/garettbass.png","language":"C","funding_links":[],"categories":["Graphics"],"sub_categories":[],"readme":"# GPUC\n\nA generic shading language compiler that writes metal, HLSL, and GLSL\n\n***GPUC is a work in progress, not ready for prime time.***\n\nThe primary motivation was to create a header-only shader language translator that has negligible effect on compile times.  Including this should not add more than a fraction of a second to your compile time, unlike other shader translators I tried.\n\nOnly the metal backend is actually useful right now, and probably only for simple shaders.  The HLSL and GLSL backends have rotted a bit due to some recent changes in the source language.\n\nI initially wrote this over a two week holiday vacation in December of 2017.  I was amazed how easy it was to continue building upon when I returned to it many months later.  For me, this was the first reasonably useful thing I implemented in C, and since then I have switched to C for the majority of my hobby projects.\n\n## Usage\n\n### Header-only library\n\n```c\n// include API declarations as needed\n#include \"gpuc/gpuc.h\"\n```\n\n```c\n// include implementation in one translation unit\n#include \"gpuc/gpuc.inl\"\n```\n\n### Stand-alone compiler\n\n```sh\n» sh gpuc.c --help\nusage:\n\n  gpuc [options] \u003csource\u003e\n\noptions:\n\n  --help           display this usage summary\n  --ast            print AST to stdout\n  --debug          print debug summary to stdout\n  --test           run tests\n  --glsl           translate GPUC to GLSL\n  --hlsl           translate GPUC to HLSL\n  --metal          translate GPUC to Metal\n  --frag \u003cfile\u003e    write output to \u003cfile\u003e, or '-' for stdout\n  --vert \u003cfile\u003e    write output to \u003cfile\u003e, or '-' for stdout\n```\n\n```sh\n» sh gpuc.c sample.gpuc --vert - --frag - --metal\n```\n```c\n#include \u003cmetal_stdlib\u003e\n#include \u003csimd/simd.h\u003e\n\nusing namespace metal;\n\nfloat4 sample(const texture2d\u003cfloat\u003e t, float2 uv) {\n    constexpr sampler s(filter::nearest);\n    return t.sample(s, uv);\n}\n\nfloat4 sample(const texture2d\u003cfloat\u003e t, float2 uv, const sampler s) {\n    return t.sample(s, uv);\n}\n\nstruct gpuc {\n\n    // float4 sample(texture2d, float2);\n\n    // float4 sample(texture2d, float2, sampler);\n\n    struct Camera {\n        float4x4 mvp;\n        float4x4 mvn;\n    };\n\n    struct Vertex {\n        float3 position [[attribute(0)]];\n        float4 color [[attribute(1)]];\n        float4 texcoords [[attribute(2)]];\n    };\n\n    struct Fragment {\n        float4 position [[position]];\n        float4 color;\n        float4 texcoords;\n    };\n\n    struct Sample {\n        float4 color;\n    };\n\n    constant const Camera\u0026 cam;\n\n    const texture2d\u003cfloat\u003e color;\n\n    const sampler samp;\n\n    Fragment vert(const Vertex v) const {\n        Fragment f;\n        f.position = cam.mvp * float4(v.position, 1);\n        f.color = v.color;\n        f.texcoords = v.texcoords;\n        return f;\n    }\n\n};\n\nvertex gpuc::Fragment vert(\n    constant const gpuc::Camera\u0026 cam [[buffer(0)]],\n    texture2d\u003cfloat\u003e color [[texture(0)]],\n    sampler samp [[sampler(0)]],\n    const gpuc::Vertex v [[stage_in]]\n) {\n    return gpuc{cam, color, samp}.vert(v);\n}\n#include \u003cmetal_stdlib\u003e\n#include \u003csimd/simd.h\u003e\n\nusing namespace metal;\n\nfloat4 sample(const texture2d\u003cfloat\u003e t, float2 uv) {\n    constexpr sampler s(filter::nearest);\n    return t.sample(s, uv);\n}\n\nfloat4 sample(const texture2d\u003cfloat\u003e t, float2 uv, const sampler s) {\n    return t.sample(s, uv);\n}\n\nstruct gpuc {\n\n    // float4 sample(texture2d, float2);\n\n    // float4 sample(texture2d, float2, sampler);\n\n    struct Camera {\n        float4x4 mvp;\n        float4x4 mvn;\n    };\n\n    struct Vertex {\n        float3 position;\n        float4 color;\n        float4 texcoords;\n    };\n\n    struct Fragment {\n        float4 position [[position]];\n        float4 color;\n        float4 texcoords;\n    };\n\n    struct Sample {\n        float4 color;\n    };\n\n    constant const Camera\u0026 cam;\n\n    const texture2d\u003cfloat\u003e color;\n\n    const sampler samp;\n\n    Sample frag(const Fragment f) const {\n        Sample s;\n        s.color = sample(color, f.texcoords.st, samp);\n        return s;\n    }\n\n};\n\nfragment gpuc::Sample frag(\n    constant const gpuc::Camera\u0026 cam [[buffer(0)]],\n    texture2d\u003cfloat\u003e color [[texture(0)]],\n    sampler samp [[sampler(0)]],\n    const gpuc::Fragment f [[stage_in]]\n) {\n    return gpuc{cam, color, samp}.frag(f);\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarettbass%2Fgpuc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarettbass%2Fgpuc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarettbass%2Fgpuc/lists"}