Skip to main content

flashraw_gpu/
lib.rs

1//! # flashraw-gpu
2//!
3//! Optional wgpu compute backend for FlashRaw (Vulkan, Metal, DX12, GL and WebGPU in
4//! the browser). It runs the post-decode pipeline on the GPU:
5//!
6//! * **unpack** of uniformly bit-packed payloads (every `PackOrder`, 1..16 bits)
7//!   straight from the file bytes, so uncompressed RAWs never touch the CPU;
8//! * **normalise** (per-position black pattern, row/column deltas, white scaling);
9//! * **develop**: one fused kernel for linearisation LUT → normalisation → bilinear /
10//!   3x3 same-colour demosaic (or 2x2 superpixel) → white balance → clip → colour
11//!   matrix → sRGB + EXIF orientation → RGBA8 (or linear f32 RGB).
12//!
13//! Results are GPU-resident [`GpuImage`]s that can be bound by the application
14//! ([`GpuImage::buffer`], [`GpuImage::to_texture`]) or downloaded.
15//!
16//! Frames of any size are supported: when a frame exceeds the adapter's storage-binding
17//! or buffer limits it is processed in pipelined horizontal bands, and outputs larger
18//! than one buffer become tiled [`GpuImage`]s ([`GpuImage::tiles`]).
19//!
20//! Every kernel has a CPU scalar reference (`flashraw::process`,
21//! `flashraw_codecs::packed`) and equivalence tests (`tests/equivalence.rs`).
22//! WGSL sources live in this crate's `shaders/` directory.
23//!
24//! ```no_run
25//! # fn main() -> flashraw_core::Result<()> {
26//! use flashraw_gpu::{GpuFrame, GpuOp};
27//! let ctx = flashraw_gpu::context()?;
28//! println!("{}", ctx.info());
29//! # let (data, info) = (vec![0u16; 16], flashraw_core::FrameInfo::new(4, 4, 12));
30//! let run = ctx.run_blocking(&GpuFrame::from_u16(&data, 4, 4, 1), &info, &GpuOp::Normalize)?;
31//! let (pixels, _ms) = run.image.download()?;
32//! # Ok(()) }
33//! ```
34
35#![deny(unsafe_code)]
36
37mod context;
38mod image;
39mod kernels;
40mod oneshot;
41pub mod policy;
42mod run;
43
44pub use context::{
45    AdapterClass, GpuAdapterInfo, GpuContext, adapter_info, available, context, init, set_context, try_context,
46};
47pub use image::{GpuImage, GpuPixelFormat, GpuTile, HostPixels};
48pub use kernels::{reference, srgb16_table, wgsl_sources};
49pub use run::{DevelopOutput, DevelopSpec, GpuCurve, GpuFrame, GpuInput, GpuOp, GpuRun, GpuTimings};
50/// Re-export of the wgpu version used, for interop.
51pub use wgpu;
52
53/// Block on a future (native only; used by the synchronous `flashraw` API).
54#[cfg(not(target_arch = "wasm32"))]
55pub fn block_on<F: std::future::Future>(f: F) -> F::Output {
56    pollster::block_on(f)
57}