ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_tile_cache.h
Go to the documentation of this file.
1
40
41#pragma once
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47#include <stdint.h>
48
49#include "ra8_err.h"
50#include "ra8_keycache.h"
51
63typedef struct {
64 uint32_t image_id;
65 uint16_t tile_x;
66 uint16_t tile_y;
67 uint16_t zoom;
68 uint16_t reserved;
70
71/* The key is compared/hashed byte-wise over sizeof(ra8_tile_key_t); guard the
72 * padding-free layout at compile time so an accidental field change cannot
73 * introduce indeterminate padding bytes into the comparison. */
74static_assert(sizeof(ra8_tile_key_t) == sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) +
75 sizeof(uint16_t) + sizeof(uint16_t),
76 "ra8_tile_key_t must be padding-free for byte-wise key comparison");
77
88typedef struct {
89 uint16_t w;
90 uint16_t h;
92
103typedef struct {
104 const uint8_t* pixels;
105 uint16_t width;
106 uint16_t height;
107} ra8_tile_t;
108
125typedef ra8_err_t (*ra8_tile_decode_fn)(void* ctx,
126 const ra8_tile_key_t* key,
127 uint8_t* cell,
128 uint32_t cell_bytes,
129 uint16_t* out_w,
130 uint16_t* out_h);
131
154
168
187
199typedef struct {
200 uint16_t tx0;
201 uint16_t ty0;
202 uint16_t tx1;
203 uint16_t ty1;
205
229
281[[nodiscard]] ra8_err_t ra8_tile_rect_of_pixels(uint32_t px,
282 uint32_t py,
283 uint32_t pw,
284 uint32_t ph,
285 uint16_t tile_w,
286 uint16_t tile_h,
287 uint16_t tile_cols,
288 uint16_t tile_rows,
289 ra8_tile_rect_t* out);
290
312
340[[nodiscard]] ra8_err_t
342
364[[nodiscard]] ra8_err_t ra8_tile_cache_put(ra8_tile_cache_t* tc, const uint8_t* pixels);
365
387[[nodiscard]] uint32_t ra8_tile_cache_capacity(const ra8_tile_cache_t* tc);
388
416
452 const ra8_tile_prefetch_req_t* req,
453 uint16_t* out_warmed);
454
477[[nodiscard]] ra8_err_t ra8_tile_cache_stats(const ra8_tile_cache_t* tc,
478 uint32_t* out_hits,
479 uint32_t* out_misses,
480 uint32_t* out_evictions);
481
482#ifdef __cplusplus
483}
484#endif
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
The one reusable hash + pin + evict cache engine (#147, #345).
ra8_err_t ra8_tile_cache_get(ra8_tile_cache_t *tc, const ra8_tile_key_t *key, ra8_tile_t *out_tile)
Get (and pin) the decoded tile for key.
ra8_err_t ra8_tile_cache_prefetch_pan(ra8_tile_cache_t *tc, const ra8_tile_prefetch_req_t *req, uint16_t *out_warmed)
Predictively warm the tiles one step ahead of a panning viewport.
ra8_err_t ra8_tile_cache_stats(const ra8_tile_cache_t *tc, uint32_t *out_hits, uint32_t *out_misses, uint32_t *out_evictions)
Report the cache hit / miss / eviction counters.
ra8_err_t ra8_tile_cache_put(ra8_tile_cache_t *tc, const uint8_t *pixels)
Release one pin on a tile previously returned by ra8_tile_cache_get.
ra8_err_t ra8_tile_cache_init(ra8_tile_cache_t *tc, const ra8_tile_cache_cfg_t *cfg)
Initialise a tile cache over caller-supplied storage.
uint32_t ra8_tile_cache_capacity(const ra8_tile_cache_t *tc)
Report the number of cells the cache can hold.
ra8_tile_pan_dir_t
Direction of viewport travel, for predictive pan prefetch.
@ k_ra8_tile_pan_none
No travel: prefetch is a no-op.
@ k_ra8_tile_pan_up
Warm the row above the viewport.
@ k_ra8_tile_pan_down
Warm the row below the viewport.
@ k_ra8_tile_pan_left
Warm the column left of the viewport.
@ k_ra8_tile_pan_right
Warm the column right of the viewport.
ra8_err_t ra8_tile_cache_prefetch(ra8_tile_cache_t *tc, const ra8_tile_key_t *key)
Warm one tile into the cache without holding a pin (read-ahead).
ra8_err_t ra8_tile_rect_of_pixels(uint32_t px, uint32_t py, uint32_t pw, uint32_t ph, uint16_t tile_w, uint16_t tile_h, uint16_t tile_cols, uint16_t tile_rows, ra8_tile_rect_t *out)
Convert a pixel rectangle into the inclusive tile rectangle covering it.
ra8_err_t(* ra8_tile_decode_fn)(void *ctx, const ra8_tile_key_t *key, uint8_t *cell, uint32_t cell_bytes, uint16_t *out_w, uint16_t *out_h)
Decode an image tile into a cache cell (decode-on-miss DIP seam).
Per-cell link metadata (one caller-owned array entry per cell).
Cache engine state (caller-owned; treat as private).
Caller-supplied storage + decoder for ra8_tile_cache_init.
ra8_tile_dims_t * dims
cell_count dimension descriptors.
uint32_t cell_bytes
Bytes per cell (max decoded tile).
ra8_tile_decode_fn decode
Decode-on-miss callback.
uint8_t * cell_mem
cell_count * cell_bytes of tile storage.
uint32_t cell_count
Number of cells.
ra8_keycache_cell_t * meta
cell_count link-metadata entries.
uint32_t bucket_count
Number of hash buckets (>= 1).
ra8_tile_key_t * keys
cell_count key-storage entries.
void * decode_ctx
Opaque context passed to decode.
int32_t * buckets
bucket_count hash-bucket heads.
Tile-cache state (caller-owned; treat as private).
ra8_keycache_t kc
Underlying keyed-LRU cache.
void * decode_ctx
Caller's decoder context.
ra8_tile_decode_fn decode
Caller's tile decoder.
Per-cell user descriptor: the decoded tile dimensions.
uint16_t h
Decoded tile height in pixels.
uint16_t w
Decoded tile width in pixels.
Identifies one decoded image tile.
uint16_t tile_y
Tile row index (in tile units).
uint16_t tile_x
Tile column index (in tile units).
uint16_t zoom
Zoom / mip level (0 = native).
uint32_t image_id
Source image identifier.
uint16_t reserved
Reserved; keep zero (padding-free byte-wise key).
A predictive pan-prefetch request: what is visible + where it heads.
uint16_t max_tiles
Residency budget: warm at most this many.
ra8_tile_rect_t view
The tiles the viewport currently straddles.
uint16_t tile_rows
Image tile rows (lead-edge clamp bound).
uint16_t zoom
Zoom / mip level for the key (0 = native).
ra8_tile_pan_dir_t dir
Direction of viewport travel.
uint32_t image_id
Tile-cache key image id (the image panned).
uint16_t tile_cols
Image tile columns (lead-edge clamp bound).
An inclusive rectangle of tile grid coordinates (the visible tiles).
uint16_t ty0
Topmost visible tile row (inclusive).
uint16_t tx1
Rightmost visible tile column (inclusive).
uint16_t ty1
Bottommost visible tile row (inclusive).
uint16_t tx0
Leftmost visible tile column (inclusive).
A pinned view of a cached tile returned by ra8_tile_cache_get.
const uint8_t * pixels
Decoded tile pixels (cell payload).
uint16_t height
Decoded tile height in pixels.
uint16_t width
Decoded tile width in pixels.