# puddingcoke/gear-engine architecture

> Architecture diagram of the GitHub repository puddingcoke/gear-engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/puddingcoke/gear-engine
- Repository: https://github.com/puddingcoke/gear-engine

## Overview

#### Purpose and entry points
Gear Engine is a Windows/Direct3D 12 graphics-and-compute engine that hides much D3D12 boilerplate behind a D3D11-like API while retaining explicit resource-state and command-list control. The primary reusable library is `Engine/Engine.vcxproj`; each demo is a separate executable. Typical application entry points are `Demos/SampleProject/main.cpp`, `Demos/SampleProject/MyGame.h`, and `Demos/SampleProject/MyRenderTask.h`.

#### Application lifecycle and execution modes
Applications initialize Gear, supply a `Gear::Game` implementation, and let the engine own the main lifecycle, window/input processing, updates, and rendering. `Game` is the application boundary; `RenderTask` is the command-recording boundary. Runtime modes include interactive window rendering, headless video rendering, and desktop-wallpaper rendering.
- `Engine/Inc/Gear/Game.h`
- `Engine/Inc/Gear/Core/RenderEngine.h`
- `Engine/Inc/Gear/InitializationParam.h`

#### D3D12 device, commands, and synchronization
The core runtime initializes the D3D12 device and records/submits graphics, compute, and video command lists. Command queues, fences, descriptor heaps, root signatures, and pipeline states are explicit engine subsystems rather than application-facing D3D12 calls. Render tasks can be created asynchronously and recorded independently; multi-thread recording is architecturally supported.
- `Engine/Inc/Gear/Core/GraphicsDevice.h`
- `Engine/Inc/Gear/Core/D3D12Core/CommandQueue.h`
- `Engine/Src/Gear/Core/RenderThread.cpp`

#### Bindless resources and automatic barriers
Resource views expose descriptor indices plus underlying-resource/subresource metadata. `GraphicsContext` consumes these pipeline-resource descriptors when constants, render targets, and shader resources are set; before draw/dispatch it resolves required states and flushes transitions. This is the central abstraction that makes high-level `draw`/`dispatch` calls manage D3D12 barriers automatically. Bindless binding requires Shader Model 6.6 `ResourceDescriptorHeap`.
- `Engine/Inc/Gear/Core/GraphicsContext.h`
- `Engine/Inc/Gear/Resource/PipelineResourceDesc.h`
- `Engine/Src/Gear/Core/D3D12Core/ResourceStateTracker.cpp`

#### Resource, shader, and pipeline construction
`ResourceManager` and resource/view classes create GPU buffers, textures, constant buffers, swap resources, upload/readback heaps, and render/depth views. Pipeline construction combines shader compilation, root signatures, and graphics/compute state through builder/helper APIs. HLSL is compiled at runtime through DXC; built-in shaders provide common fullscreen, post-process, primitive, SSR, and video conversion operations.
- `Engine/Inc/Gear/Core/ResourceManager.h`
- `Engine/Inc/Gear/Core/PipelineStateBuilder.h`
- `Engine/Inc/Gear/Core/D3D12Core/DXCCompiler.h`

#### Effects and reusable rendering stages
Effects are self-contained post-processing/rendering stages that own their shaders, PSOs, and resources behind a `process()`-style interface. Included stages cover bloom, FXAA, tone mapping, gamma/HDR handling, SSR, HBAO+, back-buffer blitting, and lat-long-to-cubemap conversion. Demos compose these with custom render tasks and shaders.
- `Engine/Inc/Gear/Effect/EffectBase.h`
- `Engine/Src/Gear/Effect/BloomEffect.cpp`
- `Engine/Src/Gear/Effect/SSREffect.cpp`

#### Demo workloads and external integration
The demos validate the engine across deferred PBR scenes, FFT ocean simulation, compute fluid simulation, particles, fractals, and wallpaper rendering. Representative compute ping-pong flows use `SwapTexture`/`SwapBuffer`; scene demos add model/material layers. The Windows-native stack includes D3D12/DXC, ImGui, DirectXTex/WIC/OpenEXR texture support, Assimp model import, NVIDIA HBAO+, FFmpeg, and NVENC/optional software video encoding.
- `Demos/CrytekSponza/SceneRenderTask.h`
- `Demos/FluidSimulation/MyRenderTask.h`
- `Engine/Inc/Gear/Core/VideoEncoder/NVIDIAEncoder.h`

Main entry points: [`Engine/Inc/Gear/Core/GraphicsContext.h`](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/GraphicsContext.h) (GraphicsContext), [`Engine/Inc/Gear/Core/RenderEngine.h`](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/RenderEngine.h) (RenderEngine), [`Demos/SampleProject/MyRenderTask.h`](https://github.com/puddingcoke/gear-engine/blob/master/Demos/SampleProject/MyRenderTask.h) (RenderTask), [`Engine/Src/Gear/Core/RenderThread.cpp`](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Src/Gear/Core/RenderThread.cpp) (Render thread)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Applications"]
  node_sample_app["Sample application<br/>demo executable<br/>[main.cpp]"]
  node_game["Game implementation<br/>application boundary<br/>[Game.h]"]
  node_render_task["RenderTask<br/>recording boundary<br/>[MyRenderTask.h]"]
end

subgraph group_runtime["Engine Runtime"]
  node_render_engine["RenderEngine<br/>lifecycle runtime<br/>[RenderEngine.h]"]
  node_init_params["Initialization parameters<br/>runtime modes"]
  node_render_thread["Render thread<br/>task scheduler<br/>[RenderThread.cpp]"]
end

subgraph group_render["Rendering Core"]
  node_graphics_device["GraphicsDevice<br/>D3D12 device<br/>[GraphicsDevice.h]"]
  node_command_queue["Command queues and fences<br/>submission sync<br/>[CommandQueue.h]"]
  node_graphics_context["GraphicsContext<br/>command recorder<br/>[GraphicsContext.h]"]
  node_pipeline_resource["Pipeline resource descriptors<br/>bindless view metadata"]
  node_state_tracker["Resource state tracker<br/>automatic barriers"]
end

subgraph group_content["Resources and Effects"]
  node_resource_manager["ResourceManager<br/>GPU resource factory<br/>[ResourceManager.h]"]
  node_pipeline_builder["Pipeline state builder<br/>PSO construction"]
  node_dxc_compiler["DXC compiler<br/>runtime HLSL compiler<br/>[DXCCompiler.h]"]
  node_effects["Effects library<br/>render stages<br/>[EffectBase.h]"]
end

subgraph group_integration["Workloads and Integration"]
  node_demo_workloads["Graphics and compute demos<br/>demo workloads<br/>[MyRenderTask.h]"]
  node_scene_rendering["Scene rendering demo<br/>model and material workload<br/>[SceneRenderTask.h]"]
  node_video_encoder["NVIDIA video encoder<br/>video integration<br/>[NVIDIAEncoder.h]"]
end

node_sample_app -->|"implements"| node_game
node_sample_app -->|"defines"| node_render_task
node_game -->|"runs in"| node_render_engine
node_init_params -->|"configures modes"| node_render_engine
node_render_engine -->|"schedules"| node_render_thread
node_render_thread -->|"records asynchronously"| node_render_task
node_render_engine -->|"initializes"| node_graphics_device
node_render_thread -->|"creates recording context"| node_graphics_context
node_render_task -->|"records draw and dispatch"| node_graphics_context
node_graphics_context -->|"binds"| node_pipeline_resource
node_graphics_context -->|"flushes transitions"| node_state_tracker
node_state_tracker -->|"prepares command lists"| node_command_queue
node_graphics_context -->|"submits through"| node_command_queue
node_resource_manager -->|"creates views"| node_pipeline_resource
node_pipeline_builder -->|"compiles shaders with"| node_dxc_compiler
node_pipeline_builder -->|"provides PSOs"| node_graphics_context
node_effects -->|"owns PSOs"| node_pipeline_builder
node_effects -->|"owns resources"| node_resource_manager
node_demo_workloads -->|"custom tasks"| node_render_task
node_demo_workloads -->|"composes"| node_effects
node_scene_rendering -->|"implements"| node_render_task
node_render_engine -.->|"headless video output"| node_video_encoder

click node_sample_app "https://github.com/puddingcoke/gear-engine/blob/master/Demos/SampleProject/main.cpp"
click node_game "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Game.h"
click node_render_task "https://github.com/puddingcoke/gear-engine/blob/master/Demos/SampleProject/MyRenderTask.h"
click node_render_engine "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/RenderEngine.h"
click node_init_params "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/InitializationParam.h"
click node_render_thread "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Src/Gear/Core/RenderThread.cpp"
click node_graphics_device "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/GraphicsDevice.h"
click node_command_queue "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/D3D12Core/CommandQueue.h"
click node_graphics_context "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/GraphicsContext.h"
click node_pipeline_resource "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Resource/PipelineResourceDesc.h"
click node_state_tracker "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Src/Gear/Core/D3D12Core/ResourceStateTracker.cpp"
click node_resource_manager "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/ResourceManager.h"
click node_pipeline_builder "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/PipelineStateBuilder.h"
click node_dxc_compiler "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/D3D12Core/DXCCompiler.h"
click node_effects "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Effect/EffectBase.h"
click node_demo_workloads "https://github.com/puddingcoke/gear-engine/blob/master/Demos/FluidSimulation/MyRenderTask.h"
click node_scene_rendering "https://github.com/puddingcoke/gear-engine/blob/master/Demos/CrytekSponza/SceneRenderTask.h"
click node_video_encoder "https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/VideoEncoder/NVIDIAEncoder.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sample_app,node_game,node_render_task toneBlue
class node_render_engine,node_init_params,node_render_thread toneAmber
class node_graphics_device,node_command_queue,node_graphics_context,node_pipeline_resource,node_state_tracker toneMint
class node_resource_manager,node_pipeline_builder,node_dxc_compiler,node_effects toneRose
class node_demo_workloads,node_scene_rendering,node_video_encoder toneIndigo
```

## Components

### Applications

- [Sample application](https://github.com/puddingcoke/gear-engine/blob/master/Demos/SampleProject/main.cpp): demo executable · `Demos/SampleProject/main.cpp`
- [Game implementation](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Game.h): application boundary · Supplies application logic to the engine lifecycle. · `Engine/Inc/Gear/Game.h`
- [RenderTask](https://github.com/puddingcoke/gear-engine/blob/master/Demos/SampleProject/MyRenderTask.h): recording boundary · Application command-recording work unit. · `Demos/SampleProject/MyRenderTask.h`

### Engine Runtime

- [RenderEngine](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/RenderEngine.h): lifecycle runtime · Owns window, input, update, and rendering lifecycle. · `Engine/Inc/Gear/Core/RenderEngine.h`
- [Initialization parameters](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/InitializationParam.h): runtime modes · Selects interactive, headless-video, or wallpaper operation. · `Engine/Inc/Gear/InitializationParam.h`
- [Render thread](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Src/Gear/Core/RenderThread.cpp): task scheduler · Supports asynchronous, independently recorded render tasks. · `Engine/Src/Gear/Core/RenderThread.cpp`

### Rendering Core

- [GraphicsDevice](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/GraphicsDevice.h): D3D12 device · Initializes the native graphics device. · `Engine/Inc/Gear/Core/GraphicsDevice.h`
- [Command queues and fences](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/D3D12Core/CommandQueue.h): submission sync · Submits graphics, compute, and video command lists. · `Engine/Inc/Gear/Core/D3D12Core/CommandQueue.h`
- [GraphicsContext](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/GraphicsContext.h): command recorder · D3D11-like draw and dispatch API over explicit command lists. · `Engine/Inc/Gear/Core/GraphicsContext.h`
- [Pipeline resource descriptors](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Resource/PipelineResourceDesc.h): bindless view metadata · Carries descriptor indices and resource/subresource metadata. · `Engine/Inc/Gear/Resource/PipelineResourceDesc.h`
- [Resource state tracker](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Src/Gear/Core/D3D12Core/ResourceStateTracker.cpp): automatic barriers · Resolves required states and flushes transitions before execution. · `Engine/Src/Gear/Core/D3D12Core/ResourceStateTracker.cpp`

### Resources and Effects

- [ResourceManager](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/ResourceManager.h): GPU resource factory · Creates buffers, textures, views, swap resources, and transfer heaps. · `Engine/Inc/Gear/Core/ResourceManager.h`
- [Pipeline state builder](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/PipelineStateBuilder.h): PSO construction · Combines shaders, root signatures, and graphics or compute state. · `Engine/Inc/Gear/Core/PipelineStateBuilder.h`
- [DXC compiler](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/D3D12Core/DXCCompiler.h): runtime HLSL compiler · Compiles shaders including SM 6.6 bindless access. · `Engine/Inc/Gear/Core/D3D12Core/DXCCompiler.h`
- [Effects library](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Effect/EffectBase.h): render stages · Self-contained bloom, SSR, AA, tone-map, and conversion stages. · `Engine/Inc/Gear/Effect/EffectBase.h`

### Workloads and Integration

- [Graphics and compute demos](https://github.com/puddingcoke/gear-engine/blob/master/Demos/FluidSimulation/MyRenderTask.h): demo workloads · Includes deferred PBR, fluid, ocean, particles, fractals, and wallpaper. · `Demos/FluidSimulation/MyRenderTask.h`
- [Scene rendering demo](https://github.com/puddingcoke/gear-engine/blob/master/Demos/CrytekSponza/SceneRenderTask.h): model and material workload · Representative deferred PBR scene integration. · `Demos/CrytekSponza/SceneRenderTask.h`
- [NVIDIA video encoder](https://github.com/puddingcoke/gear-engine/blob/master/Engine/Inc/Gear/Core/VideoEncoder/NVIDIAEncoder.h): video integration · Optional hardware video output for headless rendering. · `Engine/Inc/Gear/Core/VideoEncoder/NVIDIAEncoder.h`

## Connections

- Sample application → Game implementation: implements
- Sample application → RenderTask: defines
- Game implementation → RenderEngine: runs in
- Initialization parameters → RenderEngine: configures modes
- RenderEngine → Render thread: schedules
- Render thread → RenderTask: records asynchronously
- RenderEngine → GraphicsDevice: initializes
- Render thread → GraphicsContext: creates recording context
- RenderTask → GraphicsContext: records draw and dispatch
- GraphicsContext → Pipeline resource descriptors: binds
- GraphicsContext → Resource state tracker: flushes transitions
- Resource state tracker → Command queues and fences: prepares command lists
- GraphicsContext → Command queues and fences: submits through
- ResourceManager → Pipeline resource descriptors: creates views
- Pipeline state builder → DXC compiler: compiles shaders with
- Pipeline state builder → GraphicsContext: provides PSOs
- Effects library → Pipeline state builder: owns PSOs
- Effects library → ResourceManager: owns resources
- Graphics and compute demos → RenderTask: custom tasks
- Graphics and compute demos → Effects library: composes
- Scene rendering demo → RenderTask: implements
- RenderEngine → NVIDIA video encoder: headless video output
