{"id":17791232,"url":"https://github.com/schell/crabslab","last_synced_at":"2025-03-16T15:31:35.688Z","repository":{"id":215507825,"uuid":"738854746","full_name":"schell/crabslab","owner":"schell","description":"Slabcraft for crabs","archived":false,"fork":false,"pushed_at":"2024-10-15T20:07:57.000Z","size":1647,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-17T06:02:05.554Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/schell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-01-04T07:45:41.000Z","updated_at":"2024-10-15T20:08:02.000Z","dependencies_parsed_at":"2024-02-07T23:26:56.466Z","dependency_job_id":"2e53dc13-a46d-43c2-9d99-8bb0c43ff494","html_url":"https://github.com/schell/crabslab","commit_stats":null,"previous_names":["schell/crabslab"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fcrabslab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fcrabslab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fcrabslab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fcrabslab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schell","download_url":"https://codeload.github.com/schell/crabslab/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221665390,"owners_count":16860238,"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-10-27T10:50:19.931Z","updated_at":"2024-10-27T10:50:20.605Z","avatar_url":"https://github.com/schell.png","language":"Rust","readme":"\u003cdiv style=\"float: right; padding: 1em;\"\u003e\n    \u003cimg src=\"https://github.com/schell/crabslab/blob/main/crates/crabslab/crabslab.png?raw=true\" alt=\"slabcraft for crabs\" width=\"256\" /\u003e\n\u003c/div\u003e\n\n## What\n\n`crabslab` is a slab implementation focused on marshalling data between CPUs and GPUs.\n\n[See the example below](#example).\n\n## But Why?\nIt's hard to get data onto GPUs in the form you expect.\n\nTo marshall your data correctly you must know about the alignment and sizes of the underlying representation of your data.\nThis will often surprise you!\n\nWorking with a slab on the other hand, only requires that your types can be written into an array and read from an array.\n\n### Opinion\nWorking with _shaders_ is much easier using a slab.\n\nShader code can be written in Rust with [`rust-gpu`](https://github.com/EmbarkStudios/rust-gpu),\nwhich will enable you to use this crate on both CPU and GPU code.\n\n### rust-gpu\nThis crate was made to work with [`rust-gpu`](https://github.com/EmbarkStudios/rust-gpu/).\nSpecifically, with this crate it is possible to pack your types into a buffer on the CPU\nand then read your types from the slab on the GPU (in Rust).\n\n### Other no-std platforms\nEven though this crate was written with `rust-gpu` in mind, it should work in other `no-std`\ncontexts.\n\n## And How\nThe idea is simple - `crabslab` helps you manage a heap of contiguous `u32`s (roughly in the form of `Vec\u003cu32\u003e`). \nTypes implement the trait `SlabItem` which writes the type into an index of the slab as contiguous `u32`s and also \nreads them out symmetrically. \n\n`crabslab` includes:\n* a few traits:\n  - `Slab`\n  - `GrowableSlab`\n  - `SlabItem`\n* a derive macro for `SlabItem` for your types\n* a few new structs for working with slabs\n  - `Id`\n  - `Array`\n  - `Offset`\n* a helper struct `CpuSlab` which wraps anything implementing `GrowableSlab`\n* feature for deriving `SlabItem` for `glam` types\n\n# Example\n```rust\nuse crabslab::{CpuSlab, Slab, GrowableSlab, SlabItem, Id};\nuse glam::{Vec3, Vec4};\n\n#[derive(Debug, Default, SlabItem, PartialEq)]\nstruct Light {\n    direction: Vec3,\n    color: Vec4,\n    inner_cutoff: f32,\n    outer_cutoff: f32,\n    is_on: bool\n}\n\nimpl Light {\n    fn standard() -\u003e Self {\n        Light {\n            direction: Vec3::NEG_Z, // pointing down\n            color: Vec4::ONE, // white\n            inner_cutoff: 0.5,\n            outer_cutoff: 2.6,\n            is_on: true\n        }\n    }\n}\n\nfn cpu_code() -\u003e (Id\u003cLight\u003e, Vec\u003cu32\u003e) {\n    let light = Light::standard();\n    // Create a new slab on the CPU-side.\n    // Using CpuSlab make `append` unambiguous, as `Vec` has its own `append` function.\n    let mut slab = CpuSlab::new(vec![]);\n    let id = slab.append(\u0026light);\n    (id, slab.into_inner())\n}\n\nfn shader_code(light_id: Id\u003cLight\u003e, slab: \u0026[u32]) {\n    let light = slab.read(light_id);\n    assert_eq!(Light::standard(), light);\n}\n\nlet (light_id, slab) = cpu_code();\n// marshalling your data depends on which GPU library you are using...\nshader_code(light_id, \u0026slab);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschell%2Fcrabslab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschell%2Fcrabslab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschell%2Fcrabslab/lists"}