{"id":20185031,"url":"https://github.com/derschmale/spirv4web","last_synced_at":"2025-04-10T06:08:26.860Z","repository":{"id":45028917,"uuid":"449024517","full_name":"DerSchmale/spirv4web","owner":"DerSchmale","description":"A TypeScript SpirV to GLSL compiler for WebGL 1 and 2","archived":false,"fork":false,"pushed_at":"2022-02-16T18:43:17.000Z","size":4451,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-21T12:12:51.511Z","etag":null,"topics":["glslangvalidator","shaders","spirv","spirv-cross","webgl","webgl2"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DerSchmale.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}},"created_at":"2022-01-17T19:34:00.000Z","updated_at":"2024-06-26T14:04:02.000Z","dependencies_parsed_at":"2022-07-13T03:00:30.821Z","dependency_job_id":null,"html_url":"https://github.com/DerSchmale/spirv4web","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/DerSchmale%2Fspirv4web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerSchmale%2Fspirv4web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerSchmale%2Fspirv4web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerSchmale%2Fspirv4web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DerSchmale","download_url":"https://codeload.github.com/DerSchmale/spirv4web/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224556927,"owners_count":17331088,"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":["glslangvalidator","shaders","spirv","spirv-cross","webgl","webgl2"],"created_at":"2024-11-14T03:10:44.825Z","updated_at":"2024-11-14T03:10:46.193Z","avatar_url":"https://github.com/DerSchmale.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spir-V for Web\n\nA Spir-V to GLSL compiler for use with WebGL 1 and 2.\n\nThis is a partial TypeScript port of [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross).\nMainly built for my own use case, which is writing a single shader (in GLSL ES 3.1) and being able to convert it to WebGL 1 and 2.\nAs such, **this is very much still in an alpha stage!**\n\n## Usage\n\n### Installation\n\nInstall the package as a dependency:\n\n```\nnpm install @derschmale/spirv4web \n```\n\nor\n\n```\nyarn add @derschmale/spirv4web\n```\n\n### Javascript\n\n```\n\nimport { compile, Version } from \"@derschmale/spirv4web\";\n\nasync function yourLoadingCode(filename)\n{\n    // ...\n    // load your data into some array buffer\n    // ...    \n    return arrayBuffer;\n}\n\n// the compile function expects data in an ArrayBuffer\nconst spirv = await yourLoadingCode(\"someFilename.spv\");\n\nconst glslCode = compile(spirv, Version.WebGL2, {\n    // options (see below)\n    removeAttributeLayouts: true\n});\n\n```\n\n### Options\n\nThe `compile` function has the following signature:\n\n```\nfunction compile(data: ArrayBuffer, version: Version, options?: Options): string\n```\n\n- `data`: An ArrayBuffer containing valid Spir-V bytecode.\n- `version`: Either `Version.WebGL1` or `Version.WebGL2`\n- `options`: An optional object containing the following optional fields:\n  - `removeUnused`: Removes unused variables and resources. Defaults to `true`.\n  - `specializationConstantPrefix`: [Specialization constants](https://www.khronos.org/registry/vulkan/specs/1.1-khr-extensions/html/chap10.html#pipelines-specialization-constants) will be converted to `#define` macros. This allows setting a custom prefix for the macro names (defaults to `SPIRV_CROSS_CONSTANT_ID_`).\n  - `keepUnnamedUBOs`: This keeps unnamed uniform blocks. If `false`, UBOs will have a temporary name assigned to them. If `true`, in WebGL 1, this will turn the members of unnamed uniform buffers into global uniforms. Defaults to `true`.\n  - `removeAttributeLayouts`: (WebGL2 only) Strips layout information from vertex attributes. This is useful when you've defined more attributes than supported (Depending on `gl.MAX_VERTEX_ATTRIBS`) but not all of them are used. Defaults to `false`.\n\n## Generating Spir-V\n\nYou need `glslangValidator`, available in the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/) to convert shader code to Spir-V bytecode. \nYou can use whatever source language is supported, but results when compiling to WebGL may vary depending on the language and version. \nI've had the best results using GLSL ES 3.1 (`#version 310 es`), using the following settings:\n\n```\nglslangValidator some.frag.glsl -o some.frag.spv -e main -G -v --auto-map-locations -S frag\n```\n\n## Building\n\nIf, for some reason, you need to run a custom build, run:\n\n```\nnpm install\nnpm run build\n```\n\n## What's next?\n\nThere are still a couple of features I want to prioritize, such as:\n- Providing a list of available extensions and optionally emitting fallbacks (for example: texture2DLod -\u003e texture2D) if a feature is not supported.\n- Prune the library code for unsupported features for smaller build sizes.\n- At some point... WebGPU support.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderschmale%2Fspirv4web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderschmale%2Fspirv4web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderschmale%2Fspirv4web/lists"}