{"id":17062150,"url":"https://github.com/recp/gpu","last_synced_at":"2025-03-22T17:31:24.956Z","repository":{"id":72428137,"uuid":"175977118","full_name":"recp/gpu","owner":"recp","description":"🔭 cross platform general purpose GPU library - optimized for rendering","archived":false,"fork":false,"pushed_at":"2024-09-03T13:42:55.000Z","size":1910,"stargazers_count":33,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-18T13:51:16.447Z","etag":null,"topics":["2d","3d","c","directx","gpu","gpu-acceleration","gpu-apis","gpu-computing","gpu-library","graphics","graphics-engine","metal","opengl","render-engine","renderer","rendering","rendering-engine","shader","vulkan"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/recp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["recp"],"patreon":"recp","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2019-03-16T13:43:39.000Z","updated_at":"2024-12-05T19:51:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"909af3e7-4c4a-47e2-983e-9c0c9c54dd73","html_url":"https://github.com/recp/gpu","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/recp%2Fgpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Fgpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Fgpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recp%2Fgpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/recp","download_url":"https://codeload.github.com/recp/gpu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244995170,"owners_count":20544299,"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":["2d","3d","c","directx","gpu","gpu-acceleration","gpu-apis","gpu-computing","gpu-library","graphics","graphics-engine","metal","opengl","render-engine","renderer","rendering","rendering-engine","shader","vulkan"],"created_at":"2024-10-14T10:49:19.240Z","updated_at":"2025-03-22T17:31:24.402Z","avatar_url":"https://github.com/recp.png","language":"C","funding_links":["https://github.com/sponsors/recp","https://patreon.com/recp"],"categories":[],"sub_categories":[],"readme":"# 🔭 GPU - Cross platform GPU library (based on Metal API)\n\nThis is cross platform GPU library based on Apple's Metal API. \nLibrary is written in C language and it provides and will provide C API.\nSince this is C API, language bindings can be written for any language.\n\n## Platforms ( In Progress )\n\n- [ ] Metal\n- [ ] DirectX 12\n- [ ] Vulkan\n- [ ] WebGPU\n- [ ] ...\n\n## Status (In Progress)\n\nI'll announce after first release is ready.\n\n## Shading Language\n\nI'll try to create new shading language that called (\"Universal Shading Language\") (https://github.com/UniversalShading).\nGPU library will use that high level language for shading. Shading language will be translated/compiled into GLSL, HLSL or Metal Shaders...\nSince GPU library will be cross platform, this will also make shading language cross platform... \n\n## Design (TODO)\n\nGPU library provides `GPUApi` structure and headers. In theory any GPU API e.g. Metal, Vulkan, DirectX, OpenGL... could be bind this GPU library. \n\nSwitching between GPU APIs will be easy: `GPUSwitchGPUApi(GPU_BACKEND_METAL);` or auto select `GPUSwitchGPUApiAuto()`.\n\nThis section and others will be documented in detail later...\n\n## Naming Conventions\n\n**TODO:** `GPUSetFrontFace()` vs `gpuSetFrontFace()` vs `gpu_set_frontface()`, [feedbacks](https://github.com/recp/gpu/issues/1)\n\n## Samples\n\nComing Soon.\n\n#### - (void)viewDidLoad\n```C\n\n  GPUSwitchGPUApi(GPU_BACKEND_METAL);\n\n  device   = GPUCreateSystemDefaultDevice();\n  pipeline = GPUNewPipeline(GPUPixelFormatBGRA8Unorm_sRGB);\n  library  = GPUDefaultLibrary(device);\n\n  vertFunc = GPUShaderFunction(library, \"vertexShader\");\n  fragFunc = GPUShaderFunction(library, \"fragmentShader\");\n  vert     = GPUNewVertexDesc();\n\n  GPUAttrib(vert, VertexAttributePosition, GPUFloat3, 0, BufferIndexMeshPositions);\n  GPUAttrib(vert, VertexAttributeTexcoord, GPUFloat2, 0, BufferIndexMeshGenerics);\n\n  GPULayout(vert, BufferIndexMeshPositions, 12, 1, GPUPerVertex);\n  GPULayout(vert, BufferIndexMeshGenerics,  8,  1, GPUPerVertex);\n\n  GPUSetFunction(pipeline, vertFunc, GPU_FUNCTION_VERT);\n  GPUSetFunction(pipeline, fragFunc, GPU_FUNCTION_FRAG);\n  GPUSetVertexDesc(pipeline, vert);\n\n  GPUColorFormat(pipeline, 0, (GPUPixelFormat)_view.colorPixelFormat);\n  GPUDepthFormat(pipeline, (GPUPixelFormat)_view.depthStencilPixelFormat);\n  GPUStencilFormat(pipeline, (GPUPixelFormat)_view.depthStencilPixelFormat);\n  GPUSampleCount(pipeline, (uint32_t)_view.sampleCount);\n\n  renderState          = GPUNewRenderState(device, pipeline);\n  depthStencil         = GPUNewDepthStencil(GPUCompareFunctionLess, true);\n  depthStencilState    = GPUNewDepthStencilState(device, depthStencil);\n\n  dynamicUniformBuffer = GPUNewBuffer(device, uniformBufferSize, GPUResourceStorageModeShared);\n  commandQueue         = GPUNewCommandQueue(device);\n```\n\n#### - drawInMTKView\n\n```C\n\n- (void)drawInMTKView:(nonnull MTKView *)view {\n  dispatch_semaphore_wait(_inFlightSemaphore, DISPATCH_TIME_FOREVER);\n  \n  cmdb = GPUNewCommandBuffer(commandQueue, _inFlightSemaphore, cmdOnComplete);\n  \n  [self _updateDynamicBufferState];\n  [self _updateGameState];\n  \n  if ((pass = GPUPassFromMTKView(view))) {\n    GPURenderCommandEncoder *rce;\n\n    rce = GPUNewRenderCommandEncoder(cmdb, pass);\n    {\n      GPUSetFrontFace(rce, GPUWindingCounterClockwise);\n      GPUSetCullMode(rce, GPUCullModeBack);\n      GPUSetRenderState(rce, renderState);\n      GPUSetDepthStencil(rce, depthStencilState);\n\n      GPUSetVertexBuffer(rce, dynamicUniformBuffer, uniformBufferOffset, BufferIndexUniforms);\n      GPUSetFragmentBuffer(rce, dynamicUniformBuffer, uniformBufferOffset, BufferIndexUniforms);\n      GPUSetFragmentTexture(rce, _colorMap, TextureIndexColor);\n      \n      GPULoadAndDrawMTKMesh(rce, _mesh);\n    }\n\n    GPUEndEncoding(rce);\n    GPUPresent(cmdb, view.currentDrawable);\n  }\n\n  GPUCommit(cmdb);\n}\n```\n\n\u003cp align=\"center\"\u003e\n   \u003cimg alt=\"\" src=\"sample.png\"  /\u003e\n\u003c/p\u003e\n\n### Trademarks\n\nApple name/logo and Metal are trademarks of Apple Inc. Vulkan and OpeenGL are trademarks of Khronos Group. DirectX is trademark of Microsoft Corp.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecp%2Fgpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frecp%2Fgpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecp%2Fgpu/lists"}