Expand description
wgpu rendering backend for FerroChart: the primary backend for desktop and
the web (Vulkan, Metal, DX12, WebGPU; WebGL2 with the webgl feature).
- Series data lives on the GPU in chunks of 4096 elements with frozen
f64 reference prices. Only chunks that are drawn are uploaded; data
changes are pulled with
changes_sinceand only dirty ranges rewritten. Panning and zooming update a few uniforms and issue one instanced draw per visible chunk. - Shaders mirror
transform_helpersoperation by operation (src/shaders/series.wgsl), so this backend matches the CPU backend’s golden images. - Layer cache: background and main layers are rendered into an offscreen texture that is reused while their revisions do not change; crosshair-only frames redraw just the overlay on top of it.
- Vertex buffers are bound at the first visible element of each chunk and
instances always start at 0 (no
first_instance, so WebGL2 works the same way); no storage buffers are used.
§Examples
Offscreen rendering with read-back (the same mode tests use):
use ferrochart_core::chart::{SeriesData, SeriesOptions};
use ferrochart_core::frame::SeriesKind;
use ferrochart_core::geom::SizeCss;
use ferrochart_core::render::Renderer;
use ferrochart_core::testing::random_walk;
use ferrochart_core::{Chart, ChartOptions};
use ferrochart_render_wgpu::{GpuContext, WgpuRenderer};
let ctx = GpuContext::headless()?;
let mut renderer = WgpuRenderer::offscreen(&ctx);
let mut chart = Chart::new(ChartOptions::default());
chart.resize(SizeCss { w: 800.0, h: 450.0 }, 1.0);
let id = chart.add_series(chart.main_pane(), SeriesKind::Candlestick, SeriesOptions::default())?;
chart.set_data(id, SeriesData::Ohlc(random_walk(1, 1000, 0, 60_000)?))?;
chart.build_frame(0.0, &renderer.measurer());
renderer.render(chart.frame(), &chart.data_view())?;
let rgba = renderer.read_pixels()?;
assert_eq!(rgba.len(), 800 * 450 * 4);Structs§
- Engine
Measurer - Adapts a
TextEngineto the core’sTextMeasurer. - GpuContext
- A wgpu instance, adapter, device and queue.
- GpuSeries
Ctx - What a
GpuSeriesgets to prepare a draw. - Wgpu
Renderer - The wgpu renderer.
Traits§
- GpuSeries
- A native implementation of a custom series kind.