{"id":13836107,"url":"https://github.com/felipeagc/tinyshader","last_synced_at":"2026-01-17T12:50:09.035Z","repository":{"id":154006818,"uuid":"287642664","full_name":"felipeagc/tinyshader","owner":"felipeagc","description":"Small, easy-to-integrate shader compiler written in C99. Compiles HLSL to SPIR-V","archived":false,"fork":false,"pushed_at":"2021-03-04T23:31:06.000Z","size":994,"stargazers_count":41,"open_issues_count":2,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-21T17:19:11.425Z","etag":null,"topics":["c","compiler","hlsl","shader","spir-v","vulkan"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/felipeagc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-08-14T23:27:42.000Z","updated_at":"2023-12-03T14:16:09.000Z","dependencies_parsed_at":"2024-01-13T16:45:03.645Z","dependency_job_id":"effcc045-1782-4ff9-a8d0-8d1482f694d1","html_url":"https://github.com/felipeagc/tinyshader","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/felipeagc%2Ftinyshader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipeagc%2Ftinyshader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipeagc%2Ftinyshader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipeagc%2Ftinyshader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felipeagc","download_url":"https://codeload.github.com/felipeagc/tinyshader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225638956,"owners_count":17500656,"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":["c","compiler","hlsl","shader","spir-v","vulkan"],"created_at":"2024-08-04T15:00:35.711Z","updated_at":"2026-01-17T12:50:08.962Z","avatar_url":"https://github.com/felipeagc.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# Tinyshader\n**Lightweight, easy to embed HLSL to SPIR-V compiler written in C99**\n\n## Using the command-line compiler\nThe command-line compiler sources are located under the folder `tsc` and\ncan be used as follows:\n\n```\nUsage: tsc \u003cinput file path\u003e\n    --shader-stage | -T \u003cvertex|fragment|compute\u003e\n    --entry-point | -E \u003centry point name\u003e\n    -o \u003coutput file path\u003e\n```\n\n## Using the compiler as a library\nThe compiler library sources are located under the folder `tinyshader` and\ncan be used as follows:\n\n```c\n#include \"tinyshader.h\"\n\nTsCompilerOptions *options = tsCompilerOptionsCreate();\n\ntsCompilerOptionsSetStage(options, TS_SHADER_STAGE_VERTEX);\n\nconst char *entry_point = \"main\";\ntsCompilerOptionsSetEntryPoint(options, entry_point, strlen(entry_point));\n\ntsCompilerOptionsSetSource(\n    options,\n    hlsl_source,\n    strlen(hlsl_source),\n    path, // optional, can be NULL\n    strlen(path) // if path is NULL, this should be zero\n);\n\nTsCompilerOutput *output = tsCompile(options);\n\n/*\n * 'errors' is a null-terminated string containing compiler error messages.\n * If it's NULL, compilation was successful.\n */\nconst char *errors = tsCompilerOutputGetErrors(output);\nif (errors)\n{\n    printf(\"%s\\n\", errors);\n    exit(1);\n}\n\n/*\n * Now we have SPIR-V code, ready to pass to Vulkan.\n * NOTE: the spirv pointer is owned by TsCompilerOutput and is freed when it's destroyed.\n */\nsize_t spirv_byte_size;\nconst unsigned char *spirv = tsCompilerOutputGetSpirv(output, \u0026spirv_byte_size);\n\n// Cleanup\ntsCompilerOutputDestroy(output);\ntsCompilerOptionsDestroy(options);\n```\n\n## Compiling\nCompiling tinyshader is very simple, you just need to compile the `tinyshader/tinyshader_*.c`\nfiles (except `tinyshader/tinyshader_unity.c`), no complicated build system involved.\nAlternatively you can also compile `tinyshader/tinyshader_unity.c` to compile all of\nthe files in one go.\n\n## Goals and implemented features\nThe goal of this compiler is to be as compatible as possible with\n[DXC](https://github.com/microsoft/DirectXShaderCompiler), implementing most of its features,\nwhile being very lightweight in terms of code size.\n\nSo far, though, only a subset of HLSL features are supported.\nYou can check out the progress in [this issue](https://github.com/felipeagc/tinyshader/issues/1).\n\nRegarding optimization and quality of the generated code,\ntinyshader is supposed to provide 80% of what you need for\n10% of the code, so more advanced optimization is not planned as of now.\n\n## Vulkan resource binding\n\n### Descriptor set/binding mapping\nDescriptor binding information can either be automatic\n(using only descriptor set 0 and incremented bindings)\nor explicit through the `[[vk::binding(binding, set)]]` attribute.\n\nHLSL register bindings are currently ignored.\n\nExamples of resource binding:\n\n```hlsl\nConstantBuffer\u003cUniform\u003e gInput; // Binding: 0, Set: 0\nTexture2D gInput2; // Binding: 1, Set: 0\nSamplerState gInput3; // Binding: 2, Set: 0\n```\n\n```hlsl\n[[vk::binding(0)]] ConstantBuffer\u003cUniform\u003e gInput; // Binding: 0, Set: 0\n[[vk::binding(1)]] Texture2D gInput2; // Binding: 1, Set: 0\n[[vk::binding(2)]] SamplerState gInput3; // Binding: 2, Set: 0\n```\n\n```hlsl\n[[vk::binding(0)]] ConstantBuffer\u003cUniform\u003e gInput; // Binding: 0, Set: 0\n[[vk::binding(1, 0)]] Texture2D gInput2; // Binding: 1, Set: 0\n[[vk::binding(2, 1)]] SamplerState gInput3; // Binding: 2, Set: 1\n```\n\n### Stage inputs/outputs\nYou can either pass the stage inputs/outputs as individual parameters or put them in a struct, where\neach struct member occupies a location.\nYou can also use the returned value of a function as the stage output.\n\nExamples of stage inputs/outputs:\n\n```hlsl\nvoid main(\n    in float4 pos : POSITION, // Input location: 0\n    in float2 uv : TEXCOORD0, // Input location: 1\n    out float4 out_color : SV_Target // Output location: 0\n) {\n    out_color = 1.0f;\n}\n```\n\n```hlsl\nstruct PSInput\n{\n    float4 pos : POSITION; // Input location: 0\n    float4 sv_pos : SV_Position; // Same as gl_FragCoord from GLSL, doesn't count as an input location\n    float2 uv : TEXCOORD0; // Input location: 1\n};\n\nfloat4 main(in PSInput ps_in) : SV_Target {\n    return float4(ps_in.uv, 0.0, 1.0); // Outputs to location 0\n}\n```\n\n## License\nThis library is available to anybody free of charge, under the terms of MIT License\n(see [LICENSE](https://github.com/felipeagc/tinyshader/blob/master/LICENSE)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipeagc%2Ftinyshader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelipeagc%2Ftinyshader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipeagc%2Ftinyshader/lists"}