How aydin-aghaliyev/mandel_on_gpu works
Project type & purpose (from README + tree)
This is a native macOS command-line C++ program that generates a Mandelbrot set image using a Metal compute shader for performance, then likely writes the result as a BMP.
Key signals:
• main.cpp → C++ CLI entrypoint / orchestration.
• shader.metal → GPU compute kernel (Metal Shading Language).
• bmp.c, bmp.h → CPU-side bitmap encoding/writing (BMP output).
• metal-cpp/ → Apple-provided C++ headers/wrappers for Metal/Foundation/QuartzCore (vendored dependency).
CLI/User → Host Application
• Inputs: width/height, maxIterations, complex plane bounds, output path
Host Application → Metal Runtime
• “Create MTLDevice / MTLCommandQueue”
• “Create MTLBuffer/MTLTexture for output”
• “Create MTLComputePipelineState from metallib/function”
Metal Runtime → GPU Compute Kernel
• “Dispatch threadgroups / threads (per pixel)”
GPU Compute Kernel → GPU Output Resource
• Writes: RGBA bytes or float values → buffer/texture
Host Application ← GPU Output Resource
• “Synchronize / blit / shared memory / readback”
• Output: CPU-accessible pixel array
Host Application → BMP Encoder
• Input: pixel array + dimensions
• Output: BMP byte stream
BMP Encoder → Filesystem
• Writes: output.bmp
Build-time dependency flow (often forgotten, but key here)
• shader.metal → (metal compiler) → *.metallib → packaged next to binary or embedded
• main.cpp + bmp.c → (clang/clang++) → executable
• Executable → links against Metal/Foundation (system frameworks)
Architectural patterns/design principles to highlight
• Heterogeneous compute: CPU orchestrates; GPU performs data-parallel kernel.
• Batch/offline rendering (headless): no UI loop, just compute → encode → exit.
• Pipeline separation:
• “Compute pipeline” (Metal)
• “Serialization pipeline” (BMP)
• Resource lifetime & synchronization:
• GPU command buffer completion → CPU readback gate (important correctness detail)
“Don’t overthink it” decomposition checklist (maximize components)
Use this checklist to ensure you didn’t collapse important details:
Runtime:
• [ ] CLI/input parameters
• [ ] Host orchestration (main.cpp)
• [ ] Metal-cpp wrapper layer (metal-cpp/)
• [ ] Metal runtime (framework)
• [ ] Compute pipeline state (kernel binding)
• [ ] GPU resources (buffer/texture)
• [ ] Synchronization point (command buffer completion / fence)
• [ ] CPU readback buffer
• [ ] BMP encoder (bmp.c)
• [ ] Output file on filesystem
Build:
• [ ] Makefile
• [ ] Shader compilation step (shader.metal → metallib)
• [ ] C/C++ compilation and link step
• [ ] Runtime artifact location of metallib (embedded vs file next to binary) *(mark as “TBD: verify in Makefile/main.cpp” if not obvious)*
Sequence: One Render Invocation (Init → Dispatch → Readback → Encode → Write)
(+ optional) 4. Build Pipeline: Makefile → metallib + executable
That combination will be detailed, accurate to this project’s structure, and readable at principal-engineer depth.