Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/recp/gpu
🔠cross platform general purpose GPU library - optimized for rendering
https://github.com/recp/gpu
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
Last synced: 11 days ago
JSON representation
🔠cross platform general purpose GPU library - optimized for rendering
- Host: GitHub
- URL: https://github.com/recp/gpu
- Owner: recp
- License: apache-2.0
- Created: 2019-03-16T13:43:39.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-03T13:42:55.000Z (2 months ago)
- Last Synced: 2024-10-15T10:49:29.604Z (24 days ago)
- 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
- Language: C
- Homepage:
- Size: 1.82 MB
- Stars: 32
- Watchers: 5
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 🔠GPU - Cross platform GPU library (based on Metal API)
This is cross platform GPU library based on Apple's Metal API.
Library is written in C language and it provides and will provide C API.
Since this is C API, language bindings can be written for any language.## Platforms ( In Progress )
- [ ] Metal
- [ ] DirectX 12
- [ ] Vulkan
- [ ] WebGPU
- [ ] ...## Status (In Progress)
I'll announce after first release is ready.
## Shading Language
I'll try to create new shading language that called ("Universal Shading Language") (https://github.com/UniversalShading).
GPU library will use that high level language for shading. Shading language will be translated/compiled into GLSL, HLSL or Metal Shaders...
Since GPU library will be cross platform, this will also make shading language cross platform...## Design (TODO)
GPU library provides `GPUApi` structure and headers. In theory any GPU API e.g. Metal, Vulkan, DirectX, OpenGL... could be bind this GPU library.
Switching between GPU APIs will be easy: `GPUSwitchGPUApi(GPU_BACKEND_METAL);` or auto select `GPUSwitchGPUApiAuto()`.
This section and others will be documented in detail later...
## Naming Conventions
**TODO:** `GPUSetFrontFace()` vs `gpuSetFrontFace()` vs `gpu_set_frontface()`, [feedbacks](https://github.com/recp/gpu/issues/1)
## Samples
Coming Soon.
#### - (void)viewDidLoad
```CGPUSwitchGPUApi(GPU_BACKEND_METAL);
device = GPUCreateSystemDefaultDevice();
pipeline = GPUNewPipeline(GPUPixelFormatBGRA8Unorm_sRGB);
library = GPUDefaultLibrary(device);vertFunc = GPUShaderFunction(library, "vertexShader");
fragFunc = GPUShaderFunction(library, "fragmentShader");
vert = GPUNewVertexDesc();GPUAttrib(vert, VertexAttributePosition, GPUFloat3, 0, BufferIndexMeshPositions);
GPUAttrib(vert, VertexAttributeTexcoord, GPUFloat2, 0, BufferIndexMeshGenerics);GPULayout(vert, BufferIndexMeshPositions, 12, 1, GPUPerVertex);
GPULayout(vert, BufferIndexMeshGenerics, 8, 1, GPUPerVertex);GPUSetFunction(pipeline, vertFunc, GPU_FUNCTION_VERT);
GPUSetFunction(pipeline, fragFunc, GPU_FUNCTION_FRAG);
GPUSetVertexDesc(pipeline, vert);GPUColorFormat(pipeline, 0, (GPUPixelFormat)_view.colorPixelFormat);
GPUDepthFormat(pipeline, (GPUPixelFormat)_view.depthStencilPixelFormat);
GPUStencilFormat(pipeline, (GPUPixelFormat)_view.depthStencilPixelFormat);
GPUSampleCount(pipeline, (uint32_t)_view.sampleCount);renderState = GPUNewRenderState(device, pipeline);
depthStencil = GPUNewDepthStencil(GPUCompareFunctionLess, true);
depthStencilState = GPUNewDepthStencilState(device, depthStencil);dynamicUniformBuffer = GPUNewBuffer(device, uniformBufferSize, GPUResourceStorageModeShared);
commandQueue = GPUNewCommandQueue(device);
```#### - drawInMTKView
```C
- (void)drawInMTKView:(nonnull MTKView *)view {
dispatch_semaphore_wait(_inFlightSemaphore, DISPATCH_TIME_FOREVER);
cmdb = GPUNewCommandBuffer(commandQueue, _inFlightSemaphore, cmdOnComplete);
[self _updateDynamicBufferState];
[self _updateGameState];
if ((pass = GPUPassFromMTKView(view))) {
GPURenderCommandEncoder *rce;rce = GPUNewRenderCommandEncoder(cmdb, pass);
{
GPUSetFrontFace(rce, GPUWindingCounterClockwise);
GPUSetCullMode(rce, GPUCullModeBack);
GPUSetRenderState(rce, renderState);
GPUSetDepthStencil(rce, depthStencilState);GPUSetVertexBuffer(rce, dynamicUniformBuffer, uniformBufferOffset, BufferIndexUniforms);
GPUSetFragmentBuffer(rce, dynamicUniformBuffer, uniformBufferOffset, BufferIndexUniforms);
GPUSetFragmentTexture(rce, _colorMap, TextureIndexColor);
GPULoadAndDrawMTKMesh(rce, _mesh);
}GPUEndEncoding(rce);
GPUPresent(cmdb, view.currentDrawable);
}GPUCommit(cmdb);
}
```
### Trademarks
Apple name/logo and Metal are trademarks of Apple Inc. Vulkan and OpeenGL are trademarks of Khronos Group. DirectX is trademark of Microsoft Corp.