{"id":16224728,"url":"https://github.com/pannapudi/compaster","last_synced_at":"2025-07-29T09:35:40.742Z","repository":{"id":37092031,"uuid":"438310301","full_name":"pannapudi/compaster","owner":"pannapudi","description":"Rasterization using compute shaders","archived":false,"fork":false,"pushed_at":"2024-07-12T07:57:39.000Z","size":190,"stargazers_count":21,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T18:41:47.525Z","etag":null,"topics":["compute","gpu","rasterization","shaders","wgpu"],"latest_commit_sha":null,"homepage":"","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/pannapudi.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":"2021-12-14T15:46:38.000Z","updated_at":"2025-01-11T16:16:21.000Z","dependencies_parsed_at":"2024-10-27T20:43:34.914Z","dependency_job_id":null,"html_url":"https://github.com/pannapudi/compaster","commit_stats":null,"previous_names":["pannapudi/compaster"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pannapudi%2Fcompaster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pannapudi%2Fcompaster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pannapudi%2Fcompaster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pannapudi%2Fcompaster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pannapudi","download_url":"https://codeload.github.com/pannapudi/compaster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243989576,"owners_count":20379648,"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":["compute","gpu","rasterization","shaders","wgpu"],"created_at":"2024-10-10T12:25:19.831Z","updated_at":"2025-03-19T12:30:49.343Z","avatar_url":"https://github.com/pannapudi.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gpu_compute_rasterizer\n\n![monkee](./res.png)\n\nThis is a basic implementation of a rasterizer using compute shaders and [wgpu](https://github.com/gfx-rs/wgpu).\n\n## Differences\n\n1. Typed GPU buffers.\n\nFrom the CPU side I was able to utilize Rust type system and awesome crate [bytemuck](https://github.com/Lokathor/bytemuck) to have typed GPU buffers.\n\nWebGPU (and any other graphics API) has strict rules for memory alignment. \n`Vec3` vector types having size of 12 (3 * size_of(f32)) bytes has an alignment of 16, same as `Vec4`. And for Rust, all structs have to be marked as `#[repr(C)]` it prevents from shuffling fields for the sake of size optimization and the alighment checked by `Pod` and `Zeroable` traits provided by `bytemuck`.\n\n2. Render one fullscreen triangle instead of quad.\n\nHaving to render a fullscreen quad (or something that fills the whole screen required in `present.wgsl` shader to copy buffer content on screen.\n\nAdvantages of using fullscreen triangle is it only requires 3 vertex shader invocations (instead of 6 for a quad made up of two triangles) and less code(but not simpler).\n\n```rust\n[[stage(vertex)]]\nfn vs_main_trig([[builtin(vertex_index)]] vertex_idx: u32) -\u003e VertexOutput {\n  let uv = vec2\u003cu32\u003e((vertex_idx \u003c\u003c 1u) \u0026 2u, vertex_idx \u0026 2u);\n  let out = VertexOutput(vec4\u003cf32\u003e(1.0 - 2.0 * vec2\u003cf32\u003e(uv), 0.0, 1.0));\n  return out;\n}\n```\n\n3. More types in shaders\n\nI also tried to simplify buffer access by creating `Pixel` struct, but that didn't work well, because we can't currently have atomic operations and types on non `scalar types` by wgsl spec. \n\n```rust\n  let p = color_buffer.value[index];\n\n  let pixel = pixel_to_vec(p);\n\n  let col = vec4\u003cf32\u003e(pixel, 1.0);\n```\n  \noriginal\n```rust\n  let index = u32(X + Y * uniforms.screenWidth) * 3u;\n\n  let R = f32(finalColorBuffer.data[index + 0u]) / 255.0;\n  let G = f32(finalColorBuffer.data[index + 1u]) / 255.0;\n  let B = f32(finalColorBuffer.data[index + 2u]) / 255.0;\n\n  let finalColor = vec4\u003cf32\u003e(R, G, B, 1.0);\n```\n\nAlso I tried to add look_at camera, but currently didn't get any success in it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpannapudi%2Fcompaster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpannapudi%2Fcompaster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpannapudi%2Fcompaster/lists"}