{"id":16717782,"url":"https://github.com/nholland94/spirv-ocaml","last_synced_at":"2025-04-10T06:50:53.675Z","repository":{"id":74283432,"uuid":"79867749","full_name":"nholland94/spirv-ocaml","owner":"nholland94","description":"A code-generated SPIR-V compiler for ocaml.","archived":false,"fork":false,"pushed_at":"2018-07-20T02:47:24.000Z","size":105,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T07:56:51.950Z","etag":null,"topics":["code-generator","compiler","graphics","ocaml","ocaml-library","parallel-computing","spir-v"],"latest_commit_sha":null,"homepage":"","language":"OCaml","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/nholland94.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-24T01:40:32.000Z","updated_at":"2022-10-25T07:39:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"e578e9b3-7e17-4fe4-8402-29ca87c495a3","html_url":"https://github.com/nholland94/spirv-ocaml","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nholland94%2Fspirv-ocaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nholland94%2Fspirv-ocaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nholland94%2Fspirv-ocaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nholland94%2Fspirv-ocaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nholland94","download_url":"https://codeload.github.com/nholland94/spirv-ocaml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248173852,"owners_count":21059595,"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":["code-generator","compiler","graphics","ocaml","ocaml-library","parallel-computing","spir-v"],"created_at":"2024-10-12T21:33:41.200Z","updated_at":"2025-04-10T06:50:53.666Z","avatar_url":"https://github.com/nholland94.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spirv-ocaml\n\nA code-generated spirv compiler for ocaml.\n\n[![Build Status](https://travis-ci.org/nholland94/spirv-ocaml.svg?branch=master)](https://travis-ci.org/nholland94/spirv-ocaml)\n\n## Status\n\nThe library is ready for use and is available on [opam](https://opam.ocaml.org/packages/spirv/).\n\nThings to do:\n  - add 64 bit float literal support\n  - add validations\n\n## Warnings\n\nThis library currently does not perform any validation on the code being generated, so invalid programs will easily compile. It is recommended to check the output of this with the `spirv-val` tool from the Khronos SpirV tools repository.\n\n## Usage\n\nSpirV operations are specified using label variants (the number of spirv operations exceeds the ocaml type tag size, so a normal type variant won't work). SpirV enumerants are represented as OCaml type variants. For the case of flag types, enumerants are represented as a list of flags. Enumerants that normally specify extended operands wrap the extended operands as a tuple of arguments to the OCaml type constructor. Literal integers are represented with the `int32` type (for `int32` literals, add an `l` at the end; e.g. `10l`). Literal strings are represented with regular OCaml strings.\n\nWhen specifying literal values to the `OpConstant` instruction, the values are wrapped with the `big_int_or_float` type (there is no check against the return type of `OpConstant` right now). The default op for a `OpSpecConstantOp` instruction is specified using the type `spec_op`. The values of `spec_op` are the valid `OpSpecConstantOp` instructions, except that the result type and result are removed and the `Op` prefix is removed (e.g. ```OpSpecConstantOp (type_id, result_id, `IAdd (constant_a, constant_b))``).\n\nExtended instructions are currently implemented through a function abstraction. The extended instruction and it's operands are specified with a function in `OpExtInst` which has the type signature `unit -\u003e int32 list`. The idea behind this is that extended instructions can be provided through other OCaml libraries which would return the compiled instruction and operands as a list of SpirV words.\n\n## Example\n\n```ocaml\nlet _ =\n  let open SpirV in\n  let copy_shader_instructions = [\n    `OpCapability CapabilityShader;\n    `OpMemoryModel (AddressingModelLogical, MemoryModelSimple);\n    `OpEntryPoint (ExecutionModelGLCompute, func, \"f\", [v_in; v_out; v_g_index]);\n    `OpExecutionMode (func, ExecutionModeLocalSize (1l, 1l, 1l));\n\n    `OpDecorate (t_struct, DecorationBufferBlock);\n    `OpDecorate (v_g_index, DecorationBuiltIn BuiltInGlobalInvocationId);\n    `OpDecorate (v_in, DecorationDescriptorSet 0l);\n    `OpDecorate (v_in, DecorationBinding 0l);\n    `OpDecorate (v_out, DecorationDescriptorSet 0l);\n    `OpDecorate (v_out, DecorationBinding 1l);\n    `OpDecorate (t_in_arr, DecorationArrayStride 4l);\n    `OpMemberDecorate (t_struct, 0l, DecorationOffset 0l);\n\n    `OpTypeVoid t_void;\n    `OpTypeFunction (t_func, t_void, []);\n    `OpTypeInt (t_int, 32l, 1l);\n\n    `OpConstant (t_int, c_zero, BigInt (Big_int.big_int_of_int 0));\n    `OpConstant (t_int, c_in_sz, BigInt (Big_int.big_int_of_int 2048));\n\n    `OpTypeArray (t_in_arr, t_int, c_in_sz);\n    `OpTypeStruct (t_struct, [t_in_arr]);\n    `OpTypeVector (t_vec, t_int, 3l);\n    `OpTypePointer (t_u_struct_p, StorageClassUniform, t_struct);\n    `OpTypePointer (t_u_int_p, StorageClassUniform, t_int);\n    `OpTypePointer (t_in_vec_p, StorageClassInput, t_vec);\n    `OpTypePointer (t_in_int_p, StorageClassInput, t_int);\n\n    `OpVariable (t_u_struct_p, v_in, StorageClassUniform, None);\n    `OpVariable (t_u_struct_p, v_out, StorageClassUniform, None);\n    `OpVariable (t_u_struct_p, v_g_index, StorageClassInput, None);\n\n    `OpFunction (t_void, func, [FunctionControlNone], t_func);\n    `OpLabel label;\n    `OpAccessChain (t_in_int_p, g_index_p, v_g_index, [c_zero]);\n    `OpLoad (t_int, g_index, g_index_p, None);\n    `OpAccessChain (t_u_int_p, in_p, v_in, [c_zero; g_index]);\n    `OpAccessChain (t_u_int_p, out_p, v_out, [c_zero; g_index]);\n    `OpLoad (t_int, input, in_p, None);\n    `OpStore (out_p, input, None);\n    `OpReturn;\n    `OpFunctionEnd\n  ] in\n\n  let copy_shader = compile_to_words copy_shader_instructions in\n  ... (* do some work with compiled shader module *)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnholland94%2Fspirv-ocaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnholland94%2Fspirv-ocaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnholland94%2Fspirv-ocaml/lists"}