# openasic-org/xk265 architecture

> Architecture diagram of the GitHub repository openasic-org/xk265, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openasic-org/xk265
- Repository: https://github.com/openasic-org/xk265

## Overview

This repository implements an HEVC/H.265 hardware encoder for 8-bit YUV 4:2:0 video. Its documented workflow is to accept video and encoding settings, analyze and predict coding units, reconstruct and filter the encoded picture, then produce a CABAC bitstream. The graph uses top-level and subsystem names from the tree and capabilities documented in the README; source excerpts were unavailable, so internal call wiring is not asserted.

Main entry points: [`rtl/top/enc_core.v`](https://github.com/openasic-org/xk265/blob/master/rtl/top/enc_core.v) (Encoder core), [`rtl/rec/rec_top.v`](https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_top.v) (Reconstruction), [`rtl/top/enc_top.v`](https://github.com/openasic-org/xk265/blob/master/rtl/top/enc_top.v) (Encoder top), [`rtl/cabac/cabac_top.v`](https://github.com/openasic-org/xk265/blob/master/rtl/cabac/cabac_top.v) (CABAC coding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Encoder control"]
  node_enc_top["Encoder top<br/>[enc_top.v]"]
  node_enc_core["Encoder core<br/>[enc_core.v]"]
  node_rate["Rate control<br/>[rate_control.v]"]
end

subgraph group_analysis["Picture analysis"]
  node_fetch["Frame fetch<br/>[fetch_top.v]"]
  node_prei["Intra analysis<br/>[prei_top.v]"]
  node_ime["Integer motion<br/>[ime_top.v]"]
  node_fme["Fractional motion<br/>[fme_top.v]"]
  node_posi["Partition decisions<br/>[posi_top.v]"]
end

subgraph group_coding["Coding and reconstruction"]
  node_rec["Reconstruction<br/>[rec_top.v]"]
  node_tq["Transform quantize<br/>[tq_top.v]"]
  node_intra["Intra prediction<br/>[intra_top.v]"]
  node_mc["Motion compensation<br/>[mc_top.v]"]
end

subgraph group_output["Bitstream and filtering"]
  node_cabac["CABAC coding<br/>[cabac_top.v]"]
  node_db["Deblock and SAO<br/>[dbsao_top.v]"]
end

subgraph group_state["Buffers and memory"]
  node_mem[("On-chip memories")]
end

node_input(("Video and settings"))
node_bitstream["HEVC bitstream"]

node_input -->|"supplies frames/settings"| node_enc_top
node_enc_top -->|"starts encoding"| node_enc_core
node_enc_core -->|"fetches picture data"| node_fetch
node_enc_core -->|"analyzes intra modes"| node_prei
node_enc_core -->|"searches motion"| node_ime
node_enc_core -->|"refines motion"| node_fme
node_enc_core -->|"selects partitions"| node_posi
node_enc_core -->|"reconstructs coding units"| node_rec
node_rec -->|"transforms and quantizes"| node_tq
node_rec -->|"predicts intra blocks"| node_intra
node_rec -->|"predicts inter blocks"| node_mc
node_enc_core -->|"codes syntax"| node_cabac
node_cabac -->|"emits bitstream"| node_bitstream
node_enc_core -->|"filters reconstructed picture"| node_db
node_enc_core -->|"controls CTU rate"| node_rate
node_enc_core -->|"uses buffers"| node_mem

click node_enc_top "https://github.com/openasic-org/xk265/blob/master/rtl/top/enc_top.v"
click node_enc_core "https://github.com/openasic-org/xk265/blob/master/rtl/top/enc_core.v"
click node_fetch "https://github.com/openasic-org/xk265/blob/master/rtl/fetch/fetch_top.v"
click node_prei "https://github.com/openasic-org/xk265/blob/master/rtl/prei/prei_top.v"
click node_ime "https://github.com/openasic-org/xk265/blob/master/rtl/ime/ime_top.v"
click node_fme "https://github.com/openasic-org/xk265/blob/master/rtl/fme/fme_top.v"
click node_posi "https://github.com/openasic-org/xk265/blob/master/rtl/posi/posi_top.v"
click node_rec "https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_top.v"
click node_tq "https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_tq/tq_top.v"
click node_intra "https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_intra/intra_top.v"
click node_mc "https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_mc/mc_top.v"
click node_cabac "https://github.com/openasic-org/xk265/blob/master/rtl/cabac/cabac_top.v"
click node_db "https://github.com/openasic-org/xk265/blob/master/rtl/db/dbsao_top.v"
click node_mem "https://github.com/openasic-org/xk265/tree/master/rtl/mem"
click node_rate "https://github.com/openasic-org/xk265/blob/master/rtl/prei/rate_control.v"

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_enc_top,node_enc_core,node_rate toneBlue
class node_fetch,node_prei,node_ime,node_fme,node_posi toneAmber
class node_rec,node_tq,node_intra,node_mc toneMint
class node_cabac,node_db toneRose
class node_mem,node_input,node_bitstream toneIndigo
```

## Components

### Encoder control

- [Encoder top](https://github.com/openasic-org/xk265/blob/master/rtl/top/enc_top.v): `rtl/top/enc_top.v`
- [Encoder core](https://github.com/openasic-org/xk265/blob/master/rtl/top/enc_core.v): `rtl/top/enc_core.v`
- [Rate control](https://github.com/openasic-org/xk265/blob/master/rtl/prei/rate_control.v): `rtl/prei/rate_control.v`

### Picture analysis

- [Frame fetch](https://github.com/openasic-org/xk265/blob/master/rtl/fetch/fetch_top.v): `rtl/fetch/fetch_top.v`
- [Intra analysis](https://github.com/openasic-org/xk265/blob/master/rtl/prei/prei_top.v): `rtl/prei/prei_top.v`
- [Integer motion](https://github.com/openasic-org/xk265/blob/master/rtl/ime/ime_top.v): `rtl/ime/ime_top.v`
- [Fractional motion](https://github.com/openasic-org/xk265/blob/master/rtl/fme/fme_top.v): `rtl/fme/fme_top.v`
- [Partition decisions](https://github.com/openasic-org/xk265/blob/master/rtl/posi/posi_top.v): `rtl/posi/posi_top.v`

### Coding and reconstruction

- [Reconstruction](https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_top.v): `rtl/rec/rec_top.v`
- [Transform quantize](https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_tq/tq_top.v): `rtl/rec/rec_tq/tq_top.v`
- [Intra prediction](https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_intra/intra_top.v): `rtl/rec/rec_intra/intra_top.v`
- [Motion compensation](https://github.com/openasic-org/xk265/blob/master/rtl/rec/rec_mc/mc_top.v): `rtl/rec/rec_mc/mc_top.v`

### Bitstream and filtering

- [CABAC coding](https://github.com/openasic-org/xk265/blob/master/rtl/cabac/cabac_top.v): `rtl/cabac/cabac_top.v`
- [Deblock and SAO](https://github.com/openasic-org/xk265/blob/master/rtl/db/dbsao_top.v): `rtl/db/dbsao_top.v`

### Buffers and memory

- [On-chip memories](https://github.com/openasic-org/xk265/tree/master/rtl/mem): `rtl/mem`

### Other components

- **Video and settings**
- **HEVC bitstream**

## Connections

- Video and settings → Encoder top: supplies frames/settings
- Encoder top → Encoder core: starts encoding
- Encoder core → Frame fetch: fetches picture data
- Encoder core → Intra analysis: analyzes intra modes
- Encoder core → Integer motion: searches motion
- Encoder core → Fractional motion: refines motion
- Encoder core → Partition decisions: selects partitions
- Encoder core → Reconstruction: reconstructs coding units
- Reconstruction → Transform quantize: transforms and quantizes
- Reconstruction → Intra prediction: predicts intra blocks
- Reconstruction → Motion compensation: predicts inter blocks
- Encoder core → CABAC coding: codes syntax
- CABAC coding → HEVC bitstream: emits bitstream
- Encoder core → Deblock and SAO: filters reconstructed picture
- Encoder core → Rate control: controls CTU rate
- Encoder core → On-chip memories: uses buffers
